By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,930 Members | 2,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,930 IT Pros & Developers. It's quick & easy.

Help with Tkinter Windows

P: 2
Hello

I am currently designing my first GUI and am having difficulties opening and closing new windows. I have been looking for ideas for sometime now, however when ever I fit them into my code it does not seem to work.

What I am trying to do is open up a fresh window when a button is clicked and closing or hiding the master window.

I've attached my code and any assistance would be appriciated.

B
Attached Files
File Type: txt examplecode.txt (1.3 KB, 283 views)
Mar 23 '11 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 621
You can use withdraw and deiconify on a frame. A simple example that will close and open a Frame or a top level/root ("window" is a generic term and not specific enough for your question). You can also create an entirely new frame within Toplevel with a button click's callback.
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2.  
  3. class TestClass():
  4.  
  5.    def __init__(self):
  6.       self.top = Tkinter.Tk()
  7.       self.top.title("Test")
  8.       self.top.geometry("200x150+500+5")
  9.  
  10.       frame_1 = Tkinter.Toplevel()
  11.       frame_1.title("frame 1")
  12.  
  13.       but_1 = Tkinter.Button(self.top, text='DeIconify',                        
  14.               command=frame_1.deiconify)                                        
  15.       but_1.pack(side="bottom", fill=Tkinter.X, expand=1) 
  16.  
  17.       but_2 = Tkinter.Button(self.top, text='Quit',
  18.               command=self.top.quit, bg='blue', fg='yellow')
  19.       but_2.pack(side="bottom", fill=Tkinter.X, expand=1)
  20.  
  21.       can_1 = Tkinter.Canvas(frame_1)
  22.       can_1.pack()
  23.       can_1.create_rectangle(50,50,100,100, outline='white', fill='black')
  24.  
  25.       cont = Tkinter.Button(frame_1, text='Withdraw',
  26.               command=frame_1.withdraw, bg='red', fg='white' )
  27.       cont.pack(side="bottom", fill=Tkinter.X, expand=1)
  28.  
  29.  
  30.       self.top.mainloop()
  31.  
  32. ##====================================================================
  33. if __name__ == '__main__':
  34.    CT=TestClass() 
Mar 23 '11 #2

P: 2
Hi dwblas

Many thanks for taking the time to reply. I'm not sure if the code you have sent will do what I intend it to.

Effectivley, upon the click of a button I would like one frame to close and also another frame to open a bit like a 'next' button.

Kind regards

B
Mar 23 '11 #3

Expert 100+
P: 621
Use deiconify (or destroy) to close one frame, and add a new Frame class for the new window.
Mar 23 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.