473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with Tkinter Windows

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, 356 views)
Mar 23 '11 #1
3 2436
dwblas
626 Expert 512MB
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
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
dwblas
626 Expert 512MB
Use deiconify (or destroy) to close one frame, and add a new Frame class for the new window.
Mar 23 '11 #4

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

Similar topics

5
by: Ali | last post by:
When I open a window using the Tkinter GUI thing the title bar always says "Tk". I would like to know how to change this. I would also like to know how to cjange it on any other popup windows I may...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
5
by: Blair Hall | last post by:
I have a requirement to prevent 'accidental' tampering with some software written in Python. If I ensure that all of the modules concerned are compiled into .pyc's, and remove the .py's to another...
0
by: ³Â Ñô | last post by:
I write a program with Python 2.4 + Tkinter Execute it, there will be a window show something. If I minimize it, it will be minimized to the taskbar. But I would like it to miniminze to the System...
7
by: Simon Harvey | last post by:
Hi everyone, I need to make a service that monitors a directory for changes in the files contained within it. I have two questions: 1. I'm going to be using a FileSystemWatcher object to do...
4
by: Carl Fenley | last post by:
I believe I have almost successfully created a custom datagrid control. The new class builds without error. I have added it as reference to the main Windows Application project. It appears on...
2
by: Sabin Finateanu | last post by:
Hi! Can anyone tell me where can I find a complete Windows Versions List. I want to make a program that will identify the Windows Service Pack based on the build and revision number. Can anyone...
1
by: Hank | last post by:
I am writing a windows service in C#.NET which will manage image capturing devices, when client connects to the service, at some point the service need to expose a device dialog to the client for...
7
by: Protected | last post by:
Hello. I'm a complete newbie trying to learn Python. I decided to try some Tkinter examples, including the one from the library reference, but they don't seem to do anything! Shouldn't there be,...
0
by: William McBrine | last post by:
So, basically what I'm doing is this: window1 = Tkinter.Tk() .... window1.destroy() .... window2 = Tkinter.Tk() This works well in Linux and Mac OS X (and the PyGtk equivalent works on all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.