473,756 Members | 4,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter pack Problem

Hi,

I am struggling to get the pack method to do what I intend.
I am trying to display user input in a seperate window, along with
a little description of the field, something like this:

Current entry
Company : entered co. name
First entry : entered stuff
The second entry: more entered stuff
Entry number three : Last entered stuff

This seems so simple - but I have now spent a day or two mucking around -
and no matter what I do with the side, after and anchor parameters,
I just seem to get weird results - I must be doing something terribly stupid,
but I cant see it

So I have boiled the thing down as far as I can. - to an entry window with a
start and quit button,
one entry method, and the display window for the entered content - aside from
displaying, the programme does nothing.

Its doing the same thing on Linux and on Windows

This code should run and illustrate the hassles I am having:

8<-----------------------------start of code section--------------------------

#!/usr/bin/python
# The original of this module is supposed to do an accounting entry -

# we get the gui stuff

from Tkinter import *

class Entryscreen(Fra me):
"""This screen is used to construct a new Entry."""

# we define the variables we use

des_string = '' # Description of what we want to do
req_string = '' # Prompt string
dis_string = '' # Description of field for display

Company = "New Entry Screen" # we dont have a company yet
Entry_1 = '' # or any entries
Entry_2 = ''
Entry_3 = ''

def start_new(self) :
"""This is the routine that assembles a new record"""

if self.Company == "New Entry Screen": # if its the first time,

# we make a new window

show = Tk()
show.title('Acc ounting entry display window')

# we get an instance to display results in

self.disp = Showscreen("Cur rent entry",master=s how)

# then we ask for the company:

des_string = "Getting the Company "
req_string = "Enter the Company for this session"
dis_string = 'Company:'
error = self.GetEntry(d es_string, req_string, dis_string, self.disp)
self.Company = self.Amount

# Then or else we ask for entry details

des_string = "Getting first entry"
req_string = "Enter first field"
dis_string = "First entry:"
error = self.GetEntry(d es_string, req_string, dis_string, self.disp)

des_string = "Getting second entry"
req_string = "Enter second field"
dis_string = "The second entry:"
error = self.GetEntry(d es_string, req_string, dis_string, self.disp)

des_string = "Getting third entry"
req_string = "Enter third field"
dis_string = "Entry number three:"
error = self.GetEntry(d es_string, req_string, dis_string, self.disp)

def GetEntry(self, des_string, req_string, dis_string, disp):
"""Entry routine for one field"""

line = Entryline(des_s tring, req_string, dis_string, disp, master=root)
error = line.mainloop()
self.Amount = line.retstring
line.destroy()

def say_bye(self):
print 'Have a nice day, Bye!'
self.quit()

def createWidgets(s elf):

self.descr = Label(self)
self.descr["text"] = self.Company
self.descr["fg"] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack ({'expand': 'yes', 'fill': 'both', "side": "top"})

Start = Button(self)
Start["text"] = "Start a new entry"
Start["fg"] = "blue"
Start['bg'] = 'green'
Start["command"] = self.start_new
Start.pack({'ex pand': 'yes', 'fill': 'both', "side": "left", 'after':
self.descr})

QUIT = Button(self)
QUIT["text"] = "QUIT"
QUIT["fg"] = "black"
QUIT['bg'] = 'red'
QUIT["command"] = self.say_bye
QUIT.pack({'exp and': 'yes', 'fill': 'both', "side": "left", 'after':
Start})

def __init__(self, master=None):
Frame.__init__( self, master)
self.pack()
self.createWidg ets()

class Showscreen(Fram e):
"""This is supposed to show the entries as they occur."""

def CreateWidgets(s elf, Description):

self.descr = Label(self)
self.descr["text"] = Description
self.descr["fg"] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack ({'expand': 'yes', 'fill': 'x', "side": "top", "anchor":
"n"})

def __init__(self, Description, master=None):
Frame.__init__( self,master)
self.pack()
self.CreateWidg ets(Description )

class Entryline(Frame ):
"""This asks for an entry from the user and displays the result"""

retstring = ''

def entryend(self,S ):
"""This gets done on carriage return and is where the hassles
originate"""

self.retstring = self.estring.ge t() # get the entered string

self.disp.Amoun t_des = Label(self.disp ) # and put it into the
display window
self.disp.Amoun t_des["text"] = self.dis_string
self.disp.Amoun t_des["fg"] = 'purple'
self.disp.Amoun t_des['bg'] = 'yellow'
self.disp.Amoun t_des.pack({'ex pand': 'yes', 'fill': 'x', "side":
"left"})

self.disp.Amoun t = Label(self.disp )
self.disp.Amoun t["text"] = self.retstring
self.disp.Amoun t["fg"] = 'blue'
self.disp.Amoun t['bg'] = 'green'
self.disp.Amoun t.pack({'expand ': 'yes', 'fill': 'x', "after":
self.disp.Amoun t_des})

self.quit() # That's it, folks

def createWidgets(s elf, des_string, req_string):
"""makes the stuff to ask the question"""

descr = Label(self)
descr["text"] = des_string
descr["fg"] = 'purple'
descr['bg'] = 'yellow'
descr.pack({'ex pand': 'yes', 'fill': 'both', "side": "top"})

req = Label(self)
req ["text"] = req_string
req ["fg"] = 'yellow'
req ['bg'] = 'blue'
req.pack({'expa nd': 'yes', 'fill': 'both', "side" :"top",'afte r':
descr})

self.estring = Entry(self)
self.estring['fg'] = 'black'
self.estring['bg'] = 'white'
self.estring.pa ck({'expand':'y es','fill': 'both', 'side': 'top',
'after': req})
self.estring.bi nd('<Key-Return>', self.entryend)
self.estring.fo cus_set()

def __init__(self, des_stringP, req_stringP, dis_stringP, dispP, master):

self.disp = dispP # keep the passed params in instance vars
self.des_string = des_stringP
self.req_string = req_stringP
self.dis_string = dis_stringP

Frame.__init__( self, master)
self.pack()
self.createWidg ets(self.des_st ring, self.req_string )

root = Tk()
root.title('Acc ounting Entry Window')
app = Entryscreen(mas ter=root)
app.mainloop()
root.destroy()

8<----------------------------------end of code section-------------------

can anybody see what I am doing wrong?

- Hendrik

Jul 26 '06 #1
5 3541
On Wed, 26 Jul 2006 12:46:39 +0200, H J van Rooyen <ma**@microcorp .co.za
wrote:
Hi,

I am struggling to get the pack method to do what I intend.
I am trying to display user input in a seperate window, along with
a little description of the field, something like this:

Current entry
Company : entered co. name
First entry : entered stuff
The second entry: more entered stuff
Entry number three : Last entered stuff
You won't be able to do that kind of layout with pack. This is - quite
obviously IMHO - a job for grid, since your widgets are arranged in a grid.

According to my experience, pack should only be used for *very* simple
layouts, such as all widgets in a single row or in a single column. Trying
to do anything else will very soon end up being a nightmare, with unneeded
frames everywhere. Learn to use grid and life will be far easier for you..

[snip]

A few comments on your code:
#!/usr/bin/python
# The original of this module is supposed to do an accounting entry -

# we get the gui stuff

from Tkinter import *

class Entryscreen(Fra me):
Why do you inherit from Frame? Apparently, you're trying to do a window.A
Frame is not a window; it's a general-purpose container for widgets. If
you want to do a window, inherit from Tk (for a main window) or from
Toplevel (for any other).
"""This screen is used to construct a new Entry."""

# we define the variables we use

des_string = '' # Description of what we want to do
req_string = '' # Prompt string
dis_string = '' # Description of field for display

Company = "New Entry Screen" # we dont have a company yet
Entry_1 = '' # or any entries
Entry_2 = ''
Entry_3 = ''

def start_new(self) :
"""This is the routine that assembles a new record"""

if self.Company == "New Entry Screen": # if its the firsttime,

# we make a new window

show = Tk()
No, we don't. We actually create a whole new tcl/tk interpreter
environment, completely independent from the one we already have, which
happens to create a new main window. Doing so is bound to cause problems
later. If you want to create a new window, instantiate Toplevel.
show.title('Acc ounting entry display window')

# we get an instance to display results in

self.disp = Showscreen("Cur rent entry",master=s how)

# then we ask for the company:

des_string = "Getting the Company "
req_string = "Enter the Company for this session"
dis_string = 'Company:'
error = self.GetEntry(d es_string, req_string, dis_string,
self.disp)
self.Company = self.Amount

# Then or else we ask for entry details

des_string = "Getting first entry"
req_string = "Enter first field"
dis_string = "First entry:"
error = self.GetEntry(d es_string, req_string, dis_string,
self.disp)

des_string = "Getting second entry"
req_string = "Enter second field"
dis_string = "The second entry:"
error = self.GetEntry(d es_string, req_string, dis_string,
self.disp)

des_string = "Getting third entry"
req_string = "Enter third field"
dis_string = "Entry number three:"
error = self.GetEntry(d es_string, req_string, dis_string,
self.disp)
This is not important, but why do you always create variables for your
strings instead of passing them directly? For example, the previous 4
lines can be written:

error = self.GetEntry(" Getting third entry", "Enter third field", "Entry
number three:", self.disp)

This would shorten your code a lot. And why do you always pass self.disp
as the last argument? This is an attribute, so using it directly inside
the GetEntry method is not a problem.
def GetEntry(self, des_string, req_string, dis_string, disp):
"""Entry routine for one field"""

line = Entryline(des_s tring, req_string, dis_string, disp,
master=root)
error = line.mainloop()
*Never* call mainloop twice in an application! This is not the way to go..
If you want to do a modal dialog, you have to use the wait_window method,
which waits for a given window to be closed.
self.Amount = line.retstring
line.destroy()

def say_bye(self):
print 'Have a nice day, Bye!'
self.quit()

def createWidgets(s elf):

self.descr = Label(self)
self.descr["text"] = self.Company
self.descr["fg"] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack ({'expand': 'yes', 'fill': 'both', "side": "top"})
This can be written:

self.descr.pack (side=TOP, fill=BOTH, expand=1)

which is shorter and IMHO clearer. TOP and BOTH are constants defined in
the Tkinter module, and passing named arguments is exactly the same as
passing a dictionary.
Start = Button(self)
Start["text"] = "Start a new entry"
Start["fg"] = "blue"
Start['bg'] = 'green'
Start["command"] = self.start_new
Again, replace the 5 last lines with:

Start = Button(self, text="Start a new entry", fg='blue', bg='green',
command=self.st art_new)
Start.pack({'ex pand': 'yes', 'fill': 'both', "side": "left",
'after':
self.descr})
(see above)
QUIT = Button(self)
QUIT["text"] = "QUIT"
QUIT["fg"] = "black"
QUIT['bg'] = 'red'
QUIT["command"] = self.say_bye
QUIT.pack({'exp and': 'yes', 'fill': 'both', "side": "left",
'after':
Start})
(see above)
def __init__(self, master=None):
Frame.__init__( self, master)
self.pack()
self.createWidg ets()

class Showscreen(Fram e):
"""This is supposed to show the entries as they occur."""

def CreateWidgets(s elf, Description):

self.descr = Label(self)
self.descr["text"] = Description
self.descr["fg"] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack ({'expand': 'yes', 'fill': 'x', "side": "top",
"anchor":
"n"})
(see above)
def __init__(self, Description, master=None):
Frame.__init__( self,master)
self.pack()
self.CreateWidg ets(Description )

class Entryline(Frame ):
"""This asks for an entry from the user and displays the result"""

retstring = ''

def entryend(self,S ):
"""This gets done on carriage return and is where the hassles
originate"""

self.retstring = self.estring.ge t() # get the entered string
You're using retstring both as a class attribute (in "retstring = ''"
above) and here as an instance attribute. This is not really wrong, but a
bit weird. If you want retstring to be a class attribute, you should
access it using Entryline.retst ring (and not self.retstring) ; If you want
it to be an instance attribute, you should remove the line "retstring =
''" above and add a line:

self.retstring = ''

in the constructor below.
>
self.disp.Amoun t_des = Label(self.disp ) # and put it into
the
display window
self.disp.Amoun t_des["text"] = self.dis_string
self.disp.Amoun t_des["fg"] = 'purple'
self.disp.Amoun t_des['bg'] = 'yellow'
self.disp.Amoun t_des.pack({'ex pand': 'yes', 'fill': 'x', "side":
"left"})
(see above)
self.disp.Amoun t = Label(self.disp )
self.disp.Amoun t["text"] = self.retstring
self.disp.Amoun t["fg"] = 'blue'
self.disp.Amoun t['bg'] = 'green'
self.disp.Amoun t.pack({'expand ': 'yes', 'fill': 'x', "after":
self.disp.Amoun t_des})
(see above)
self.quit() # That's it, folks

def createWidgets(s elf, des_string, req_string):
"""makes the stuff to ask the question"""

descr = Label(self)
descr["text"] = des_string
descr["fg"] = 'purple'
descr['bg'] = 'yellow'
descr.pack({'ex pand': 'yes', 'fill': 'both', "side": "top"})
(see above)
req = Label(self)
req ["text"] = req_string
req ["fg"] = 'yellow'
req ['bg'] = 'blue'
req.pack({'expa nd': 'yes', 'fill': 'both', "side" :"top",'afte r':
descr})
(see above)
self.estring = Entry(self)
self.estring['fg'] = 'black'
self.estring['bg'] = 'white'
self.estring.pa ck({'expand':'y es','fill': 'both', 'side': 'top',
'after': req})
self.estring.bi nd('<Key-Return>', self.entryend)
self.estring.fo cus_set()

def __init__(self, des_stringP, req_stringP, dis_stringP, dispP,
master):

self.disp = dispP # keep the passed params in instancevars
self.des_string = des_stringP
self.req_string = req_stringP
self.dis_string = dis_stringP
AFAICS, these attributes are never used. Why did you create them?
Frame.__init__( self, master)
self.pack()
self.createWidg ets(self.des_st ring, self.req_string )

root = Tk()
root.title('Acc ounting Entry Window')
app = Entryscreen(mas ter=root)
app.mainloop()
root.destroy()
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Jul 26 '06 #2
I find the "Tkinter reference: a GUI for Python" under "Local links" on
this page http://infohost.nmt.edu/tcc/help/lan...n/tkinter.html to
be very helpful. It has a decent discussion of the grid layout
manager.

HTH,
~Simon

Jul 26 '06 #3
H J van Rooyen wrote:
Hi,

I am struggling to get the pack method to do what I intend.
I am trying to display user input in a seperate window, along with
a little description of the field, something like this:

Current entry
Company : entered co. name
First entry : entered stuff
The second entry: more entered stuff
Entry number three : Last entered stuff
You can achieve this with pack(), but only by using
a lot of nested panels:

+-----------------------------------------+
| Current entry |
+-----------------------------------------+
+-----------------------------------------+
|Company : entered co. name |
+-----------------------------------------+
+-----------------------------------------+
|First entry : entered stuff|
+-----------------------------------------+
+-----------------------------------------+
|The second entry: more entered stuff |
+-----------------------------------------+
+-----------------------------------------+
|Entry number three : Last entered stuff |
+-----------------------------------------+

Create the subpanels and pack the labels
into their respective subpanels with side="left"
and the entry fields with side="right"; then
pack all the subpanels into the main window
with side="top". But this is really a PITA,
it would be simpler use grid() as Eric B suggests.
Once you learn grid(), you will probably never
need to use pack() again.

-- JK
Jul 26 '06 #4

"Eric Brunel" <er*********@de spammed.comwrot e:

|On Wed, 26 Jul 2006 12:46:39 +0200, H J van Rooyen <ma**@microcorp .co.za>
|wrote:
|
|Hi,
|>
|I am struggling to get the pack method to do what I intend.
|I am trying to display user input in a seperate window, along with
|a little description of the field, something like this:
|>
| Current entry
|Company : entered co. name
|First entry : entered stuff
|The second entry: more entered stuff
|Entry number three : Last entered stuff
|
|You won't be able to do that kind of layout with pack. This is - quite
|obviously IMHO - a job for grid, since your widgets are arranged in a grid.
|
|According to my experience, pack should only be used for *very* simple
|layouts, such as all widgets in a single row or in a single column. Trying
|to do anything else will very soon end up being a nightmare, with unneeded
|frames everywhere. Learn to use grid and life will be far easier for you.

I can kind of agree with this - If I learnt one thing it was that I can get them
in a column, or a row, or what looks like a weird kind of horizontal hierarchy,
but not what I was looking for...

|
|[snip]
|
|A few comments on your code:
|
|#!/usr/bin/python
|# The original of this module is supposed to do an accounting entry -
|>
|# we get the gui stuff
|>
|from Tkinter import *
|>
|class Entryscreen(Fra me):
|
|Why do you inherit from Frame? Apparently, you're trying to do a window. A
|Frame is not a window; it's a general-purpose container for widgets. If
|you want to do a window, inherit from Tk (for a main window) or from
|Toplevel (for any other).

No particular reason other than ignorance - the original example I was following
did something like this, and
as it actually produced something that looked to me like it was working I did
not mess with it :-)

What is the best place to get info on all these wonderful things - I have been
trying to come right by reading the module help - but its kind of cryptic... -
like most things its cool as a reminder if you already know what it does...

|
| """This screen is used to construct a new Entry."""
|>
|# we define the variables we use
|>
| des_string = '' # Description of what we want to do
| req_string = '' # Prompt string
| dis_string = '' # Description of field for display
|>
| Company = "New Entry Screen" # we dont have a company yet
| Entry_1 = '' # or any entries
| Entry_2 = ''
| Entry_3 = ''
|>
| def start_new(self) :
| """This is the routine that assembles a new record"""
|>
| if self.Company == "New Entry Screen": # if its the first time,
|>
|# we make a new window
|>
| show = Tk()
|
|No, we don't. We actually create a whole new tcl/tk interpreter
|environment, completely independent from the one we already have, which
|happens to create a new main window. Doing so is bound to cause problems
|later. If you want to create a new window, instantiate Toplevel.
|

Ok I will try it, thanks.
| show.title('Acc ounting entry display window')
|>
|# we get an instance to display results in
|>
| self.disp = Showscreen("Cur rent entry",master=s how)
|>
|# then we ask for the company:
|>
| des_string = "Getting the Company "
| req_string = "Enter the Company for this session"
| dis_string = 'Company:'
| error = self.GetEntry(d es_string, req_string, dis_string,
|self.disp)
| self.Company = self.Amount
|>
|# Then or else we ask for entry details
|>
| des_string = "Getting first entry"
| req_string = "Enter first field"
| dis_string = "First entry:"
| error = self.GetEntry(d es_string, req_string, dis_string,
|self.disp)
|>
| des_string = "Getting second entry"
| req_string = "Enter second field"
| dis_string = "The second entry:"
| error = self.GetEntry(d es_string, req_string, dis_string,
|self.disp)
|>
| des_string = "Getting third entry"
| req_string = "Enter third field"
| dis_string = "Entry number three:"
| error = self.GetEntry(d es_string, req_string, dis_string,
|self.disp)
|
|This is not important, but why do you always create variables for your
|strings instead of passing them directly? For example, the previous 4
|lines can be written:

The original code actually used the variables as globals ... *ducks*

|
|error = self.GetEntry(" Getting third entry", "Enter third field", "Entry
|number three:", self.disp)
|
|This would shorten your code a lot. And why do you always pass self.disp
|as the last argument? This is an attribute, so using it directly inside
|the GetEntry method is not a problem.

The thing was giving me all sorts of errors when I changed disp from being a
global - It prolly has to do with the bad move of having a second instance of
k - I messed around and stopped when I got no more errors - could this be what
is really meant by Heuristic Programming?

|
| def GetEntry(self, des_string, req_string, dis_string, disp):
| """Entry routine for one field"""
|>
| line = Entryline(des_s tring, req_string, dis_string, disp,
|master=root)
| error = line.mainloop()
|
|*Never* call mainloop twice in an application! This is not the way to go.
|If you want to do a modal dialog, you have to use the wait_window method,
|which waits for a given window to be closed.

What is a modal dialog, daddy? (I am not being facetious, I really wanna know)

- I am actually not closing the window - the frame with the two labels and the
entry line disappears when you hit enter, and then gets manufactured again for
the next entry - in the real app there is also a choice widget with scroll bars
that is populated from a file and that also disappears when you make a choice by
double mouse click - that is how coded things like company, document type, and
account codes would be entered in practice - the entry thingy was the simplest
thing to include to show what I was complaining about.

Will the wait_window method work for the Frame, or must it be a window? Or is
there a wait_frame method?

I am not sure I understand the mainloop bit - is this mainloop the same mainloop
as the other mainloop?
What does this mainloop actually do? - I need to pass control to the thingy that
gets the entry somehow, and wait for it to complete, and get the value that was
entered and displayed to use in the real app... - or will this happen
*automagically* because of the binding of the enter key to the entryend
method? - and I need the data before the entry thingy is destroyed so I cant let
it commit seppoku (Hara Kiri for the uninitiated) - or must I do that and then I
would have to go fetch the data out of the other window where its displayed? (if
its still there and not a reference to a destroyed thing - I find assignment in
Python a bit confusing at times...)
I was under the impression that this mainloop is tied to line and not to the
*main* instance...
I did not (and cannot) call mainloop for the second Tk instance - if I do then
app blocks until the second window is closed, and then the whole thing is
broken...

Another small issue - the binding to entryend - on Linux, I see that it binds
only the main keyboard enter key, and not the numeric pad enter key - (I did not
test this on Windows) How does one get both?

| self.Amount = line.retstring
| line.destroy()
|>
| def say_bye(self):
| print 'Have a nice day, Bye!'
| self.quit()
|>
| def createWidgets(s elf):
|>
| self.descr = Label(self)
| self.descr["text"] = self.Company
| self.descr["fg"] = 'purple'
| self.descr['bg'] = 'yellow'
| self.descr.pack ({'expand': 'yes', 'fill': 'both', "side": "top"})
|
|This can be written:
|
|self.descr.pac k(side=TOP, fill=BOTH, expand=1)
|
|which is shorter and IMHO clearer. TOP and BOTH are constants defined in
|the Tkinter module, and passing named arguments is exactly the same as
|passing a dictionary.

Thanks - did not know this and I like it - its also less to type and that is
important cos I am lazy...

|
| Start = Button(self)
| Start["text"] = "Start a new entry"
| Start["fg"] = "blue"
| Start['bg'] = 'green'
| Start["command"] = self.start_new
|
|Again, replace the 5 last lines with:
|
|Start = Button(self, text="Start a new entry", fg='blue', bg='green',
|command=self.s tart_new)

*nods*

|
| Start.pack({'ex pand': 'yes', 'fill': 'both', "side": "left",
|'after':
|self.descr})
|
|(see above)

*nods*

|
| QUIT = Button(self)
| QUIT["text"] = "QUIT"
| QUIT["fg"] = "black"
| QUIT['bg'] = 'red'
| QUIT["command"] = self.say_bye
| QUIT.pack({'exp and': 'yes', 'fill': 'both', "side": "left",
|'after':
|Start})
|
|(see above)

*nods*

|
| def __init__(self, master=None):
| Frame.__init__( self, master)
| self.pack()
| self.createWidg ets()
|>
|class Showscreen(Fram e):
| """This is supposed to show the entries as they occur."""
|>
| def CreateWidgets(s elf, Description):
|>
| self.descr = Label(self)
| self.descr["text"] = Description
| self.descr["fg"] = 'purple'
| self.descr['bg'] = 'yellow'
| self.descr.pack ({'expand': 'yes', 'fill': 'x', "side": "top",
|"anchor":
|"n"})
|
|(see above)

*nods*

|
| def __init__(self, Description, master=None):
| Frame.__init__( self,master)
| self.pack()
| self.CreateWidg ets(Description )
|>
|class Entryline(Frame ):
| """This asks for an entry from the user and displays the result"""
|>
| retstring = ''
|>
| def entryend(self,S ):
| """This gets done on carriage return and is where the hassles
|originate"""
|>
| self.retstring = self.estring.ge t() # get the entered string
|
|You're using retstring both as a class attribute (in "retstring = ''"
|above) and here as an instance attribute. This is not really wrong, but a
|bit weird. If you want retstring to be a class attribute, you should
|access it using Entryline.retst ring (and not self.retstring) ; If you want
|it to be an instance attribute, you should remove the line "retstring =
|''" above and add a line:
|
|self.retstring = ''
|
|in the constructor below.

Ok - I think it might have to be an instance thinghy really - cos it is
effectively the *return value* of what was typed - and it happens more than
once - OTOH - if I read it out of the class variable at the right time, it might
also work - there *should* only be one of these alive at any one time - or am I
talking BS?

|
|>
| self.disp.Amoun t_des = Label(self.disp ) # and put it into
|the
|display window
| self.disp.Amoun t_des["text"] = self.dis_string
| self.disp.Amoun t_des["fg"] = 'purple'
| self.disp.Amoun t_des['bg'] = 'yellow'
| self.disp.Amoun t_des.pack({'ex pand': 'yes', 'fill': 'x', "side":
|"left"})
|
|(see above)

*nods*

|
| self.disp.Amoun t = Label(self.disp )
| self.disp.Amoun t["text"] = self.retstring
| self.disp.Amoun t["fg"] = 'blue'
| self.disp.Amoun t['bg'] = 'green'
| self.disp.Amoun t.pack({'expand ': 'yes', 'fill': 'x', "after":
|self.disp.Amou nt_des})
|
|(see above)

*nods*

|
| self.quit() # That's it, folks
|>
| def createWidgets(s elf, des_string, req_string):
| """makes the stuff to ask the question"""
|>
| descr = Label(self)
| descr["text"] = des_string
| descr["fg"] = 'purple'
| descr['bg'] = 'yellow'
| descr.pack({'ex pand': 'yes', 'fill': 'both', "side": "top"})
|
|(see above)

*nods*

|
| req = Label(self)
| req ["text"] = req_string
| req ["fg"] = 'yellow'
| req ['bg'] = 'blue'
| req.pack({'expa nd': 'yes', 'fill': 'both', "side" :"top",'afte r':
|descr})
|
|(see above)

*nods*

|
| self.estring = Entry(self)
| self.estring['fg'] = 'black'
| self.estring['bg'] = 'white'
| self.estring.pa ck({'expand':'y es','fill': 'both', 'side': 'top',
|'after': req})
| self.estring.bi nd('<Key-Return>', self.entryend)
| self.estring.fo cus_set()
|>
| def __init__(self, des_stringP, req_stringP, dis_stringP, dispP,
|master):
|>
| self.disp = dispP # keep the passed params in instance vars
| self.des_string = des_stringP
| self.req_string = req_stringP
| self.dis_string = dis_stringP
|
|AFAICS, these attributes are never used. Why did you create them?

a) they used to be globals *ducks again*
b) when I was changing them from being globals I was getting errors and after I
did this the errors went away... - I just changed the names to make them formal
parameters by appending a "P"...
c) the value of self.dis_string is used above to populate the instance of
disp.Amount_des["text"] in entryend - it is needed there - the other two are
used below in the createWidgets call - but you are right - below here I could
have used them just as they were passed, like I do with master in the __init__
call

|
| Frame.__init__( self, master)
| self.pack()
| self.createWidg ets(self.des_st ring, self.req_string )
|>
|root = Tk()
|root.title('Ac counting Entry Window')
|app = Entryscreen(mas ter=root)
|app.mainloop()
|root.destroy()
|
|HTH

Yes it does - thanks for the effort

In a sense, the answer of "you cant do this with pack, use grid" is the wrong
answer, as I have spent far too much time on this - but hey, that's how you
learn...

Did you actually try to run this thing to see what it did? - from my perspective
it seems to do everything I want except that it messes up the display of the
data in the second window...

|--
|python -c "print ''.join([chr(154 - ord(c)) for c in
|'U(17zX(%,5.zm z5(17l8(%,5.Z*( 93-965$l7+-'])"

Jul 26 '06 #5

"Simon Forman" <ro*********@ya hoo.comwrote:

| I find the "Tkinter reference: a GUI for Python" under "Local links" on
| this page http://infohost.nmt.edu/tcc/help/lan...n/tkinter.html to
| be very helpful. It has a decent discussion of the grid layout
| manager.
|
| HTH,
| ~Simon

Thanks am checking it out - downloading pdf... - Hendrik

Jul 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5903
by: Thomas Nücker | last post by:
Hi! I am creating a dialog-box within my application, using tkinter. The problem is the following: After the dialogbox is started, the main application window comes again to top and the dialogbox is covered by the window of the main application and must be "fetched" again via the taskbar to continue. Is there a way to "force" the dialogbox on top of all other windows? (I'm using MSWindows and Python22) The source of my dialogbox-class...
1
5982
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
3
7035
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter import * class App:
2
3250
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make. My button bar is implemented a Frame subclass, which takes the button dictionary as an argument and displays the buttons on the screen: class OptionsBar(Frame): def __init__(self, buttonDict, parent=None) Frame.__init__(self, parent)
6
17990
by: max(01)* | last post by:
hi people. when i create a widget, such as a toplevel window, and then i destroy it, how can i test that it has been destroyed? the problem is that even after it has been destroyed, the instance still exists and has a tkinter name, so testing for None is not feasible: >>> import Tkinter >>> fin = None >>> fin1 = Tkinter.Toplevel()
0
3587
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
0
2359
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
1
2662
by: C D Wood | last post by:
To whom this may concern, Below is the source code, which demonstrates a problem I am having making a GUI for my python project work. 'table.txt' is a file that is read from the same folder. My code writes to a text file 'table.txt', and 'table.txt' is displayed in
1
3598
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
3
3918
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new window respectively having
0
9255
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,...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
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
6514
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
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3780
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
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
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.