Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105650 > unrolled thread
| Started by | kevind0718@gmail.com |
|---|---|
| First post | 2016-03-24 13:24 -0700 |
| Last post | 2016-03-25 13:03 -0400 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.python
Tkinter --> Why multiple windows kevind0718@gmail.com - 2016-03-24 13:24 -0700
Re: Tkinter --> Why multiple windows Random832 <random832@fastmail.com> - 2016-03-24 16:28 -0400
Re: Tkinter --> Why multiple windows kevind0718@gmail.com - 2016-03-24 13:43 -0700
Re: Tkinter --> Why multiple windows Terry Reedy <tjreedy@udel.edu> - 2016-03-24 21:27 -0400
Re: Tkinter --> Why multiple windows Wildman <best_lay@yahoo.com> - 2016-03-24 20:24 -0500
Re: Tkinter --> Why multiple windows kevind0718@gmail.com - 2016-03-25 06:41 -0700
Re: Tkinter --> Why multiple windows Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-25 13:03 -0400
| From | kevind0718@gmail.com |
|---|---|
| Date | 2016-03-24 13:24 -0700 |
| Subject | Tkinter --> Why multiple windows |
| Message-ID | <d1b257d3-6d27-4201-b3db-e363409b2623@googlegroups.com> |
Hello:
newbie Tkinter question
If I run the code below two windows appear.
One empty and one with the text box and button.
Why? please
KD
from Tkinter import *
class MyDialog:
def __init__(self, parent):
top = self.top = Toplevel(parent)
Label(top, text="Value").pack()
self.e = Entry(top)
self.e.pack(padx=5)
b = Button(top, text="OK", command=self.ok)
b.pack(pady=5)
def ok(self):
print "value is", self.e.get()
self.top.destroy()
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
[toc] | [next] | [standalone]
| From | Random832 <random832@fastmail.com> |
|---|---|
| Date | 2016-03-24 16:28 -0400 |
| Message-ID | <mailman.107.1458851325.2244.python-list@python.org> |
| In reply to | #105650 |
On Thu, Mar 24, 2016, at 16:24, kevind0718@gmail.com wrote: > Hello: > > newbie Tkinter question > > If I run the code below two windows appear. > One empty and one with the text box and button. The empty one is the root window.
[toc] | [prev] | [next] | [standalone]
| From | kevind0718@gmail.com |
|---|---|
| Date | 2016-03-24 13:43 -0700 |
| Message-ID | <e1dcb15a-61bb-480c-bd6e-ff4107149a53@googlegroups.com> |
| In reply to | #105651 |
On Thursday, March 24, 2016 at 4:29:03 PM UTC-4, Random832 wrote: > On Thu, Mar 24, 2016, at 16:24, kevind0718@gmail.com wrote: > > Hello: > > > > newbie Tkinter question > > > > If I run the code below two windows appear. > > One empty and one with the text box and button. > > The empty one is the root window. I kinda guessed that. Is there any downside to hiding it using root.withdraw(). thanks for quick responce. KD
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2016-03-24 21:27 -0400 |
| Subject | Re: Tkinter --> Why multiple windows |
| Message-ID | <mailman.126.1458869278.2244.python-list@python.org> |
| In reply to | #105652 |
On 3/24/2016 4:43 PM, kevind0718@gmail.com wrote: > On Thursday, March 24, 2016 at 4:29:03 PM UTC-4, Random832 wrote: >> On Thu, Mar 24, 2016, at 16:24, kevind0718@gmail.com wrote: >>> If I run the code below two windows appear. >>> One empty and one with the text box and button. >>> Why? The answer to that sort of question is nearly always "Because that is what you asked for" >> The empty one is the root window. > I kinda guessed that. > Is there any downside to hiding it using root.withdraw(). In your example, there is no apparent reason to hid root and use a Toplevel. IDLE, however, is currently a multiwindow application with no main window and it uses 'root.withdraw'. (In fact, it appears to do so twice in the IDLE process -- possibly a mistake.) -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Wildman <best_lay@yahoo.com> |
|---|---|
| Date | 2016-03-24 20:24 -0500 |
| Message-ID | <OYWdncAt39_MDmnLnZ2dnUU7-I-dnZ2d@giganews.com> |
| In reply to | #105650 |
On Thu, 24 Mar 2016 13:24:16 -0700, kevind0718 wrote:
> Hello:
>
> newbie Tkinter question
>
> If I run the code below two windows appear.
> One empty and one with the text box and button.
>
> Why? please
>
> KD
>
>
>
> from Tkinter import *
>
> class MyDialog:
> def __init__(self, parent):
>
> top = self.top = Toplevel(parent)
>
> Label(top, text="Value").pack()
>
> self.e = Entry(top)
> self.e.pack(padx=5)
>
> b = Button(top, text="OK", command=self.ok)
> b.pack(pady=5)
>
> def ok(self):
>
> print "value is", self.e.get()
>
> self.top.destroy()
>
>
> root = Tk()
>
> d = MyDialog(root)
>
> root.wait_window(d.top)
Try this:
from Tkinter import *
class MyDialog(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.pack(fill=BOTH, expand=1)
self.parent.title("MyDialog")
Label(self, text="Value").pack()
self.e = Entry(self)
self.e.pack(padx=5)
self.b = Button(self, text="OK", command=self.ok)
self.b.pack(pady=5)
def ok(self):
print "value is", self.e.get()
root = Tk()
d = MyDialog(root)
root.mainloop()
--
<Wildman> GNU/Linux user #557453
May the Source be with you.
[toc] | [prev] | [next] | [standalone]
| From | kevind0718@gmail.com |
|---|---|
| Date | 2016-03-25 06:41 -0700 |
| Message-ID | <7d191efb-fe80-488f-87db-268b4b893d42@googlegroups.com> |
| In reply to | #105673 |
On Thursday, March 24, 2016 at 9:24:44 PM UTC-4, Wildman wrote:
> On Thu, 24 Mar 2016 13:24:16 -0700, kevind0718 wrote:
>
> > Hello:
> >
> > newbie Tkinter question
> >
> > If I run the code below two windows appear.
> > One empty and one with the text box and button.
> >
> > Why? please
> >
> > KD
> >
> >
> >
> > from Tkinter import *
> >
> > class MyDialog:
> > def __init__(self, parent):
> >
> > top = self.top = Toplevel(parent)
> >
> > Label(top, text="Value").pack()
> >
> > self.e = Entry(top)
> > self.e.pack(padx=5)
> >
> > b = Button(top, text="OK", command=self.ok)
> > b.pack(pady=5)
> >
> > def ok(self):
> >
> > print "value is", self.e.get()
> >
> > self.top.destroy()
> >
> >
> > root = Tk()
> >
> > d = MyDialog(root)
> >
> > root.wait_window(d.top)
>
> Try this:
>
> from Tkinter import *
>
> class MyDialog(Frame):
>
> def __init__(self, parent):
> Frame.__init__(self, parent)
> self.parent = parent
> self.pack(fill=BOTH, expand=1)
> self.parent.title("MyDialog")
> Label(self, text="Value").pack()
> self.e = Entry(self)
> self.e.pack(padx=5)
> self.b = Button(self, text="OK", command=self.ok)
> self.b.pack(pady=5)
>
> def ok(self):
> print "value is", self.e.get()
>
> root = Tk()
> d = MyDialog(root)
> root.mainloop()
>
> --
> <Wildman> GNU/Linux user #557453
> May the Source be with you.
Looking at the lines below
As related to the code I posted above.
I believe this code will allow me to instantiate the class
MyDialog, wait until the window is destroyed and then
continue on my merry way.
root = Tk()
d = MyDialog(root)
root.wait_window(d.top)
Now if I pass an instance of Unamepword into the constructor of
MyDialog(unamepword) , I can modify uStr and pWord in MyDialog and
the local copy will get updated.
Correct?
class Unamepword:
##
## class to hold user name and pWord for Database
uName = None
pWord = None
def __init__(self, uStr, pStr):
self.uName = uStr
self.pWord = pStr
Many thanks for your attention to this matter.
KD
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2016-03-25 13:03 -0400 |
| Message-ID | <mailman.6.1458925358.28225.python-list@python.org> |
| In reply to | #105689 |
On Fri, 25 Mar 2016 06:41:48 -0700 (PDT), kevind0718@gmail.com declaimed
the following:
>class Unamepword:
> ##
> ## class to hold user name and pWord for Database
> uName = None
> pWord = None
Those are essentially useless...
> def __init__(self, uStr, pStr):
uStr and pStr are required arguments to the instance creation, and
> self.uName = uStr
> self.pWord = pStr
>
here you bind them to the instance specific uName/pWord attributes. The
class-wide uName/pWord will never be visible unless somewhere you
explicitly use
Unamepword.uName
or
Unamepword.pWord
in some method of the class, in order to bypass the instance attribute.
Since you don't show the entire class I can't comment further -- if all
it does is set those attributes you could just as easily use a dictionary
login = Unamepword("bob", "secret")
print login.uName, login.pWord
vs
login = { "uName" : "bob", "pWord" : "secret" }
print login["uName"], login["pWord"]
Note: I'm not necessarily recommending the latter -- just offering
alternatives... If you assume username is always first a simple tuple might
do
login = ("bob", "secret")
print login[0], login[1]
...
UNAME = 0
PWORD = 1
print login[UNAME], login[PWORD]
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web