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 :-

class c1 :
    def __init__:

class c2:
    def __init__:
         if user :
            root1 = Tk()   
            a2 = c1(root1)    #new application starts

root = Tk()
a = c2(root)

The error that I get is that c1 does not have Tk attribute. How can I create new screens ?
Is there any way or should I create dialogs ?
Please help ..........

To create a new screen, you could just manipulate what is on the screen already. You could delete all the objects from the current screen, and then add the new objects of the next scene. There is probably a better way to do it as that would be a little long winded.

You have several errors in your code. Firstly, you cannot destroy "root" in your c2 class, as, in the class scope, it does not exist. Also, you haven't defined the classes properly with their "__init__" functions. It should be:

def __init__(self):

Also, you are trying to pass "root1" (a Tkinter program instance), to class "c1", which takes no arguments, and has no attribute of "Tk".

The last major error is that you have

if user:

but "user" is not defined. You need to define a variable before you use it as a conditional variable.

Here's something for you to have a look at.

import os
from Tkinter import *

class C1:
	def __init__(self):
		self.root = Tk()
		print 'Root 1'
		if true:

class C2:
	def __init__(self):
		self.root1 = Tk()
		print 'Root 2'


I'm still not entirely sure what you are trying to do with the above code. Have a look at this on classes.


Please upvote it this helped and mark the thread as solved if I solved your problem.

This article has been dead for over six months. Start a new discussion instead.