Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65232 > unrolled thread

Tkinter widgets into classes.

Started byLewis Wood <fluttershy363@gmail.com>
First post2014-02-01 11:43 -0800
Last post2014-02-02 11:15 +0100
Articles 14 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Tkinter widgets into classes. Lewis Wood <fluttershy363@gmail.com> - 2014-02-01 11:43 -0800
    Re: Tkinter widgets into classes. archie65@live.co.uk - 2014-02-01 12:03 -0800
    Re: Tkinter widgets into classes. archie65@live.co.uk - 2014-02-01 12:04 -0800
    Re: Tkinter widgets into classes. Lewis Wood <fluttershy363@gmail.com> - 2014-02-01 12:12 -0800
      Re: Tkinter widgets into classes. Dave Angel <davea@davea.name> - 2014-02-01 16:52 -0500
        Re: Tkinter widgets into classes. Lewis Wood <fluttershy363@gmail.com> - 2014-02-01 14:12 -0800
          Re: Tkinter widgets into classes. Dave Angel <davea@davea.name> - 2014-02-01 17:26 -0500
            Re: Tkinter widgets into classes. Lewis Wood <fluttershy363@gmail.com> - 2014-02-01 15:07 -0800
              Re: Tkinter widgets into classes. "albert visser" <albert.visser@gmail.com> - 2014-02-02 01:46 +0100
              Re: Tkinter widgets into classes. Terry Reedy <tjreedy@udel.edu> - 2014-02-01 20:26 -0500
              Re: Tkinter widgets into classes. Christian Gollwitzer <auriocus@gmx.de> - 2014-02-02 11:22 +0100
                Re: Tkinter widgets into classes. Lewis Wood <fluttershy363@gmail.com> - 2014-02-02 12:38 -0800
                  Re: Tkinter widgets into classes. David Hutto <dwightdhutto@gmail.com> - 2014-02-02 22:21 -0500
    Re: Tkinter widgets into classes. Christian Gollwitzer <auriocus@gmx.de> - 2014-02-02 11:15 +0100

#65232 — Tkinter widgets into classes.

FromLewis Wood <fluttershy363@gmail.com>
Date2014-02-01 11:43 -0800
SubjectTkinter widgets into classes.
Message-ID<5e297400-3322-45aa-ab7e-016af083b259@googlegroups.com>
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()

[toc] | [next] | [standalone]


#65234

Fromarchie65@live.co.uk
Date2014-02-01 12:03 -0800
Message-ID<164222db-b1d9-429d-a60f-4ba421ae3006@googlegroups.com>
In reply to#65232
You become less of a a faget and stop sucking granni tranni pussi
dis shud help u lewl

[toc] | [prev] | [next] | [standalone]


#65235

Fromarchie65@live.co.uk
Date2014-02-01 12:04 -0800
Message-ID<2ef4b774-2b63-4eae-8dfa-0b91ffbab5e6@googlegroups.com>
In reply to#65232
On Saturday, 1 February 2014 19:43:18 UTC, Lewis Wood  wrote:
> 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()

[toc] | [prev] | [next] | [standalone]


#65237

FromLewis Wood <fluttershy363@gmail.com>
Date2014-02-01 12:12 -0800
Message-ID<04a9d0b0-c968-42c2-94d2-93438558e227@googlegroups.com>
In reply to#65232
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?

[toc] | [prev] | [next] | [standalone]


#65238

FromDave Angel <davea@davea.name>
Date2014-02-01 16:52 -0500
Message-ID<mailman.6289.1391291392.18130.python-list@python.org>
In reply to#65237
 Lewis Wood <fluttershy363@gmail.com> Wrote in message:
> 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.
-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#65241

FromLewis Wood <fluttershy363@gmail.com>
Date2014-02-01 14:12 -0800
Message-ID<2377621f-a208-4a12-b66c-bb678df6efcf@googlegroups.com>
In reply to#65238
On Saturday, 1 February 2014 21:52:51 UTC, Dave Angel  wrote:
> Lewis Wood <fluttershy363@gmail.com> Wrote in message:
> 
> > 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.
> 
> -- 
> 
> DaveA

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

[toc] | [prev] | [next] | [standalone]


#65242

FromDave Angel <davea@davea.name>
Date2014-02-01 17:26 -0500
Message-ID<mailman.6292.1391293398.18130.python-list@python.org>
In reply to#65241
 Lewis Wood <fluttershy363@gmail.com> Wrote in message:
> 
>> 
(deleting doublespaced googlegroups trash)
>> 
>> 
>> To put it another way, you only want one mainloop in your code.
>> 
>> -- 
>> 
>> DaveA
> 
> But I can click the button Multiple times and it will create multiple windows?
> 

Not using the function you showed. 

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#65243

FromLewis Wood <fluttershy363@gmail.com>
Date2014-02-01 15:07 -0800
Message-ID<fab76f9e-7369-4bbc-9da8-06994b731dde@googlegroups.com>
In reply to#65242
On Saturday, 1 February 2014 22:26:17 UTC, Dave Angel  wrote:
> Lewis Wood <fluttershy363@gmail.com> Wrote in message:
> 
> > 
> 
> >> 
> 
> (deleting doublespaced googlegroups trash)
> 
> >> 
> 
> >> 
> 
> >> To put it another way, you only want one mainloop in your code.
> 
> >> 
> 
> >> -- 
> 
> >> 
> 
> >> DaveA
> 
> > 
> 
> > But I can click the button Multiple times and it will create multiple windows?
> 
> > 
> 
> 
> 
> Not using the function you showed. 
> 
> 
> 
> -- 
> 
> DaveA

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()

[toc] | [prev] | [next] | [standalone]


#65245

From"albert visser" <albert.visser@gmail.com>
Date2014-02-02 01:46 +0100
Message-ID<mailman.6293.1391301979.18130.python-list@python.org>
In reply to#65243
On Sun, 02 Feb 2014 00:07:00 +0100, Lewis Wood <fluttershy363@gmail.com>  
wrote:

> On Saturday, 1 February 2014 22:26:17 UTC, Dave Angel  wrote:
>> Lewis Wood <fluttershy363@gmail.com> Wrote in message:
(snip)
>>
>> DaveA
>
> 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/

[toc] | [prev] | [next] | [standalone]


#65247

FromTerry Reedy <tjreedy@udel.edu>
Date2014-02-01 20:26 -0500
Message-ID<mailman.6295.1391304389.18130.python-list@python.org>
In reply to#65243
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.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#65255

FromChristian Gollwitzer <auriocus@gmx.de>
Date2014-02-02 11:22 +0100
Message-ID<lcl689$sb2$1@dont-email.me>
In reply to#65243
Am 02.02.14 00:07, schrieb Lewis Wood:
> 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()

I don't know how this works, but it is definitely wrong. If you need 
more than one window, use Toplevel() to create it.

	Christian

[toc] | [prev] | [next] | [standalone]


#65282

FromLewis Wood <fluttershy363@gmail.com>
Date2014-02-02 12:38 -0800
Message-ID<0bfb9c90-ee4d-42aa-b181-17b2b6dd1ea7@googlegroups.com>
In reply to#65255
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? 

[toc] | [prev] | [next] | [standalone]


#65318

FromDavid Hutto <dwightdhutto@gmail.com>
Date2014-02-02 22:21 -0500
Message-ID<mailman.6324.1391397714.18130.python-list@python.org>
In reply to#65282

[Multipart message — attachments visible in raw view] — view raw

I just happened to find this link:

http://effbot.org/tkinterbook/

through this link:

https://wiki.python.org/moin/TkInter

which ALL happened to stem from this link:

https://www.google.com/search?client=ubuntu&channel=fs&q=python+tkinter+tutorials&ie=utf-8&oe=utf-8



On Sun, Feb 2, 2014 at 3:38 PM, Lewis Wood <fluttershy363@gmail.com> wrote:

> 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?
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com <http://www.hitwebdevelopment.com>*

[toc] | [prev] | [next] | [standalone]


#65254

FromChristian Gollwitzer <auriocus@gmx.de>
Date2014-02-02 11:15 +0100
Message-ID<lcl5rq$qkc$1@dont-email.me>
In reply to#65232
Am 01.02.14 20:43, schrieb 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 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()

Well, you are on the right track, it is a good idea to structure a 
complex GUI by breaking it up into smaller functional pieces. The right 
way to do it is called "megawidget", and it's done by making a Frame 
which contains the subwidgets; e.g.

=========================
import Tkinter as Tk
import ttk

# python3:
# import tkinter as Tk
# from tkinter import ttk

class dbllabel(ttk.Frame):
	def __init__(self, parent, text1, text2):
		ttk.Frame.__init__(self, parent)
		# python3:
		# super(dbllabel, self).__init__(self, parent)
		self.l1=ttk.Label(self, text=text1)
		self.l2=ttk.Label(self, text=text2)
		self.l1.grid(row=0, column=0)
		self.l2.grid(row=1, column=0)


# now use the dbllabel in our program
# like a regular widget
root=Tk.Tk()
mainframe = ttk.Frame(root)
mainframe.pack(expand=True, fill=Tk.BOTH)

# here is no difference between making a button
# and our fresh new megawidget
foo=ttk.Button(mainframe, text="Some other widet")
bar=dbllabel(mainframe, text1="First line", text2="Second line")

foo.grid(row=0, column=0)
bar.grid(row=0, column=1)

root.mainloop()
========================

Note that
1) I only have python2 to test it here now, so there might be an error 
on the python3 parts

2) I've used ttk widgets all over where possible. This should give the 
most expected look and feel on all platforms

3) More complex megawidgets will of course also group functionality 
(i.e. reactions to button clicks etc.) in the same megawidget class

	Christian

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web