Tkinter widgets into classes.

L

Lewis Wood

I was wandering if I could dynamically change my GUI and after a few searches on Google found the grid_remove() function. What I'm wandering now is ifthere is a way to group a lot of widgets up into one, and then use the onegrid_remove function which will remove them all.

Is it possible to do this in a class like this?

class group1:
label1=Label(text="Upon clicking the button").grid(row=0,column=0)
label2=Label(text="The menu will dynamically change").grid(row=1,column=0)

group1.grid_remove()
 
A

archie65

You become less of a a faget and stop sucking granni tranni pussi
dis shud help u lewl
 
A

archie65

I was wandering if I could dynamically change my GUI and after a few searches on Google found the grid_remove() function. What I'm wandering now is if there is a way to group a lot of widgets up into one, and then use the one grid_remove function which will remove them all.



Is it possible to do this in a class like this?



class group1:

label1=Label(text="Upon clicking the button").grid(row=0,column=0)

label2=Label(text="The menu will dynamically change").grid(row=1,column=0)



group1.grid_remove()
 
L

Lewis Wood

Oh and another question, say I make another window in the program itself using this:

def secondwindow():
root2=Tk()
root2.mainloop()

Would it be possible for me to use some code which would return True if one of these windows is currently up, or return False if the window is not up?
 
D

Dave Angel

Lewis Wood said:
Oh and another question, say I make another window in the program itself using this:

def secondwindow():
root2=Tk()
root2.mainloop()

Would it be possible for me to use some code which would return True if one of these windows is currently up, or return False if the window is not up?

No need. Only one at a time can be running, and you won't return
from this function till it's done.

To put it another way, you only want one mainloop in your code.
 
L

Lewis Wood

No need. Only one at a time can be running, and you won't return

from this function till it's done.



To put it another way, you only want one mainloop in your code.

But I can click the button Multiple times and it will create multiple windows?
 
L

Lewis Wood

(deleting doublespaced googlegroups trash)





Not using the function you showed.

It does, this is the whole code:

from tkinter import *

root=Tk()
root.title("Second Root Testing")



def secondwindow():
root2=Tk()
root2.mainloop()


button1=Button(root,text="Root2",command=secondwindow).grid(row=0,column=0)



root.mainloop()
 
A

albert visser

It does, this is the whole code:

from tkinter import *

root=Tk()
root.title("Second Root Testing")



def secondwindow():
root2=Tk()
root2.mainloop()
this may seem to work, but you're starting a new event loop here instead
of using the current one. I think you want to create another TopLevel()
window here, not a new Tk instance.
button1=Button(root,text="Root2",command=secondwindow).grid(row=0,column=0)
Note that if you want to be able to actually use the button1 symbol, you
have to break this statement up:

button1=Button(root,text="Root2",command=secondwindow)
button1.grid(row=0,column=0)

You can't shortcut this because grid() returns None.
root.mainloop()


--
Vriendelijke groeten / Kind regards,

Albert Visser

Using Opera's mail client: http://www.opera.com/mail/
 
T

Terry Reedy

Idle, which used tkinter, runs multiple windows in one process with one
event loop. There is no reason I know of to run multiple event loops in
one process, and if you do, the results will not be documented and might
vary between runs or between different systems.

Idle can also be run multiple times in multiple processes, each with its
own event loop. But there is seldom a reason to do that with the same
version. On the other hand, I routinely have more than one version
running in order to test code with multiple versions. I can even have
the same file open in multiple versions.
 
L

Lewis Wood

Thanks all who replied, will look further into megawidgets and the Toplevel() function. Is there a way to get a separate window to return something when closed?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top