so i have created a program,
im not sure how to change gui screens, for example, the first screen is username/password on the opening scree, and than it will move onto the next screen where i can input data when i have enterd password correctly.

cheers

Recommended Answers

All 4 Replies

Can you show same code?
Which gui toolkit you use?

If you're using wxPython, then I wrote a heavily commented snippet below showing it. There might be a better way, but this is all I could come up with at the moment. If any other users have a different idea, please post it too!

import wx

#  First screen
class Screen1( wx.Panel ):
    def __init__( self, parent, id ):
        wx.Panel.__init__( self, parent, id )
        self.parent = parent  #  Make 'parent' accessible to all functions on this screen

        #  Widgets
        self.szr = wx.BoxSizer( wx.VERTICAL )
        self.btn = wx.Button( self, 100, "Change Screen" )  #  Make a button to change screens
        self.Bind( wx.EVT_BUTTON, self.OnChange, id=100 )  #  Bind an event to it

        #  Layout
        self.szr.Add( self.btn, 0, wx.ALIGN_CENTER )
        self.SetSizer( self.szr )
        self.SetSize( parent.GetSize() )  #  Set this panel to take up the whole frame

    #  Button event to change screens
    def OnChange( self, event ):
        parent = self.parent  #  Save the 'parent' variable before being destroyed
        self.Destroy()  #  Destroy the current panel
        Screen2( parent, -1 )  #  Set the new screen suing the saved parent variable


#  Second screen
class Screen2( wx.Panel ):
    def __init__( self, parent, id ):
        wx.Panel.__init__( self, parent, id )

        #  Widgets
        self.szr = wx.BoxSizer( wx.VERTICAL )
        self.txt = wx.StaticText( self, -1, "Panel 2" )

        #  Layout
        self.szr.Add( self.txt, 0, wx.ALIGN_CENTER )
        self.SetSizer( self.szr )
        self.SetSize( parent.GetSize() )  #  Set this panel to take up the whole frame


#  Run the app
app = wx.App()
frame = wx.Frame( None, -1, "MyGUI", size=(200, 150) )  #  Make the main application frame
Screen1( frame, -1 )  #  Make the frame show the first screen  (pass 'frame' as the parent )
frame.Centre()
frame.Show( True )
app.MainLoop()

(The comments kinda wrap around when look at it as code on the site, but paste it into your Python editor to see it better).

thanks for that so far.
we are using tkinter

Oh, tkinter. I can't really help you there then. I've only used wxPython before.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.