473,840 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create different application windows in Tkinter?

26 New Member
Hey all

I am trying to make GUI windows using Tkinter and have got stucked. Its exactly like an installation setup where you move to new windows . I have been unable to understand how to create multiple application windows in Tkinter.
I want that according to user input I should be directed to new screen belonging to a new class like follows :-

Expand|Select|Wrap|Line Numbers
  1.  
  2. class c1 :
  3.     def __init__:
  4.  
  5. class c2:
  6.     def __init__:
  7.          if user :
  8.             root.destroy()
  9.             root1 = Tk()   
  10.             a2 = c1(root1)    #new application starts
  11.  
  12. root = Tk()
  13. a = c2(root)
  14. root.mainloop()
  15.  
The error that I get is that c1 does not have Tk attribute. How can I go to new screens ?

Please help !
Nov 13 '10 #1
3 5781
dwblas
626 Recognized Expert Contributor
Start with a class that will actually run. Class C2 will not (start here for a simple example) . Then you can pass "root" to C1.
Nov 13 '10 #2
nk28
26 New Member
Hey my problem is that c2 is working fine on its own . But when I add these statements to work c1 after c2 the Tk window gets formed with the error that c1 has no Tk attribute.

What is difference between this and a2 = Toplevel(root)
Nov 13 '10 #3
dwblas
626 Recognized Expert Contributor
"C2" never receives "root" and "C1" never receives "root1"-->although root will work just as well. Take a look at the link posted above and see how root is passed to myApp and how the class receives and then uses root/myParent.

"root = Tk()" just creates a class instance of Tk and you can pass that instance around, and use everything in the Tk class instance, in as many different objects as you like.

Below is an example of a self-contained class. And some Tkinter links
http://www.ferg.org/thinking_in_tkinter/index.html
http://effbot.org/tkinterbook/
http://infohost.nmt.edu/tcc/help/pub...ter/index.html
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2.  
  3. class EntryTest:
  4.    """ shows using the same StringVar in the second list box
  5.        and in the entry box
  6.    """
  7.    def __init__(self):
  8.       self.top = Tkinter.Tk()
  9.       self.top.title("Test of Entry")
  10.       self.top.geometry("200x150+10+10")
  11.  
  12.       self.str_1 = Tkinter.StringVar()
  13.       label_lit = Tkinter.StringVar()
  14.       self.int_lit = Tkinter.IntVar()
  15.       self.int_ctr = 0
  16.  
  17.       label_1 = Tkinter.Label(self.top, textvariable = label_lit )
  18.       label_1.pack()
  19.       label_lit.set( "Test of Label")
  20.  
  21.       label_2 = Tkinter.Label(self.top, textvariable = self.str_1 )
  22.       label_2.pack()
  23.  
  24.       label_3 = Tkinter.Label(self.top, textvariable = self.int_lit )
  25.       label_3.pack()
  26.       self.int_lit.set(self.int_ctr)
  27.  
  28.       entry_1 = Tkinter.Entry(self.top, textvariable=self.str_1)
  29.       entry_1.pack()
  30.       self.str_1.set( "Entry Initial Value" )
  31.  
  32.       ##---  Delete the contents of an entry widget
  33.       ## entry.delete(0,END)
  34.  
  35.       print_button = Tkinter.Button(self.top, text='PRINT CONTENTS',
  36.                      command=self.getit, bg='blue', fg='white' )
  37.       print_button.pack(fill=Tkinter.X, expand=1)
  38.  
  39.       exit_button= Tkinter.Button(self.top, text='EXIT',
  40.                    command=self.top.quit, bg='red', fg='white' )
  41.       exit_button.pack(fill=Tkinter.X, expand=1)
  42.  
  43.       entry_1.focus_set()
  44.  
  45.       self.top.mainloop()
  46.  
  47.    ##-----------------------------------------------------------------
  48.    def getit(self) :
  49.       print "getit: variable passed =", self.str_1.get()
  50.       self.int_ctr += 1
  51.       self.int_lit.set(self.int_ctr)
  52.  
  53.  
  54. ##===============================================================
  55. if "__main__" == __name__  :
  56.    ET=EntryTest()
  57.    print "under __main__ =", ET.str_1.get() 
Nov 13 '10 #4

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

Similar topics

0
1689
by: Chung Ta | last post by:
Hi all, I am having problem creating web application using Visual Studio .Net. I encountered the following error: Unable to create Web project 'WebApp1'. Unable to validate that the file path 'C:\Inetpub\wwwroot\WebApp1' matches the URL path 'http://localhost/WebApp1'. A connection with the server could not be established.
3
16378
by: Job Lot | last post by:
Can some please provide some tips, links whatever possible on creating Graphs in WINDOWS FORMS application (not web forms), using DataSet, DataTable etc etc… anything. I am totally lost and cud not find anything helpful.
3
2621
by: Mustaq | last post by:
Hi, How to read same config file from different application? I have 4 application in VB.NET, all are using different app.config files. NOW I need all to read only one config file, how can I do this. Thanks in Adv. Regards,
2
4714
by: Robert Wille | last post by:
I have found that the sort order is different on Windows and Linux (same version of Postgres). On Windows, it sorts in what appears to be normal ASCIIorder. On Linux, lowercase comes before uppercase, and all non-alphanumerics appear to come before all alphanumerics. I really need it to sort on Linux the same as it does on Windows. The docs seem to imply that I can simplyset the LANG environment variable to C to get an ASCII sort order, but that...
1
1521
by: PABLO | last post by:
I need to use spliter in an application Windows, if they can help me with that I will thank for them very many
2
11815
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console application, DVD collection starter kit. How can I do? Any suggest? Thanks in advance. VAL
11
2329
by: rayala | last post by:
Hi all, I am having very weird problem in my Outlook I am running my web application from with in Outlook.I found a strange problem that it is creating different sessionId if i open a new window using window.open from with in my application.I am pulling my hair all along but no solution so far.Hope you guys can help me out. my application works fine when i run this in IE.It is Outlook2003
3
2176
by: psbasha | last post by:
Hi, I would like to call the same aplication executable with and without Graphical User Interface. Requirement: With Tkinter User interface,user can give the inputs to run the application ( Interactive). Instead user will have this inputs in the file and it will be read by the batch utility or exe for the application For example:
1
2111
by: qhimq | last post by:
Hi all, I need some help in understanding how to repaint multiple different child windows. The child windows opened by the user, so I have a problem right now of understanding how to have a callback procedure for an unknown amount of child windows with different painting needed to be on, on each. Tips and/or hints?
1
1709
by: Francesco Bochicchio | last post by:
Il Mon, 18 Aug 2008 12:15:10 +0100, dudeja.rajat ha scritto: Uhm, I don't think you should use the grid manager to obtain a window like that. The grid manager is for equally distributing widgets both horizontally and vertically. And I'm not sure that you can realize that window look with Tkinter. You could get close by horizontally packing each widget row in a frame and then vertically packing the frames in the window. But the look...
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9698
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10914
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10597
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.