473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Simple Tkinter problem

Hi all,

I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the previous
widgets when they pop up. How do I reinitialize the widget each time so
that it doesn't contain earlier ones? Actually, another question I have
is, is there a way to set python so that it will assume any undefined
variable is 0 or ''? That is, I have several statements like "If k 0
then so and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the program but
it seems there should be a better way.

Greg

Nov 7 '06 #1
4 1557
On 2006-11-07, gm********@gmail.com <gm********@gmail.comwrote:
I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the
previous widgets when they pop up. How do I reinitialize the
widget each time so that it doesn't contain earlier ones?
Show your code.
Actually, another question I have is, is there a way to set
python so that it will assume any undefined variable is 0 or
''? That is, I have several statements like "If k 0 then so
and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the
program but it seems there should be a better way.
The best way to do it is to never use undefined names.

--
Neil Cerutti
If only faces could talk. --Pat Summerall
Nov 7 '06 #2
Here's my Tkinter class:

class TwoChoice:
def __init__(self, master):

frame = Frame(master)
frame.pack()
m = Label(root, text= maentry)
m.pack()
n = Label(root, text= fave)
n.pack()

self.button = Button(frame, text=home_team, command=
self.comm_1)
self.button.pack(side=LEFT)

self.hi_there = Button(frame, text=vis_team,
command=self.comm_2)
self.hi_there.pack(side=LEFT)

def comm_1(self):
print home_team
root.quit()

def comm_2(self):
print vis_team
root.quit()

I call it by

root = Tk()
gui= TwoChoice(root)
root.mainloop()

The next time I call it I want to just run the same thing but with
different values for the variables. Instead it gives me like two copies
of the widget.

Greg

Neil Cerutti wrote:
On 2006-11-07, gm********@gmail.com <gm********@gmail.comwrote:
I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the
previous widgets when they pop up. How do I reinitialize the
widget each time so that it doesn't contain earlier ones?

Show your code.
Actually, another question I have is, is there a way to set
python so that it will assume any undefined variable is 0 or
''? That is, I have several statements like "If k 0 then so
and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the
program but it seems there should be a better way.

The best way to do it is to never use undefined names.

--
Neil Cerutti
If only faces could talk. --Pat Summerall
Nov 7 '06 #3

Greg,

Run the following code to see how pack_forget() or
grid_forget() works, it makes previous widgets
disappear but not go away. If you call grid() or
pack() again after using grid_forget() the widget
returns.
root = Tk()
class Ktest:
def __init__(self):
self.Ftest1()

def Ftest1(self):

try:
self.test2.grid_forget()
except AttributeError :
pass
self.test1 = Button(root, text='Push #1
button', bg = 'yellow', width = 25,
command = self.Ftest2,
height = 25)
self.test1.grid(row=0, column=0)
def Ftest2(self):
self.test1.grid_forget()
self.test2 = Button(root, text='Push #2
button', bg = 'green',
width = 15,
command = self.Ftest1,
height = 10)
self.test2.grid(row=0, column=0)

if __name__== '__main__' :
Ktest()
mainloop()

Maybe someone else has an idea about not defining
a variable.

My question is how does a budket of wires and
screws know its a bucket of wires and screws
unless someone tells it that it's a bucket of
wires and screws?


On Tuesday 07 November 2006 09:35,
gm********@gmail.com wrote:
Hi all,

I'm trying to write a GUI that will put up
multiple widgets in succession. My problem is
that each widget also contains the previous
widgets when they pop up. How do I reinitialize
the widget each time so that it doesn't contain
earlier ones? Actually, another question I have
is, is there a way to set python so that it
will assume any undefined variable is 0 or ''?
That is, I have several statements like "If k >
0 then so and so" and I would like it to assume
k=0 unless I tell it otherwise. I've just been
defining k=0 at the start of the program but it
seems there should be a better way.

Greg
Nov 7 '06 #4
On Tuesday 07 November 2006 10:38, jim-on-linux
wrote:
Greg,

Run the following code to see how pack_forget()
or grid_forget() works, it makes previous
widgets disappear but not go away. If you call
grid() or pack() again after using
grid_forget() the widget returns.
root = Tk()
class Ktest:
def __init__(self):
self.Ftest1()

def Ftest1(self):

try:
self.test2.grid_forget()
except AttributeError :
pass
self.test1 = Button(root, text='Push #1
button', bg = 'yellow',
width = 25,
command = self.Ftest2, height = 25)
self.test1.grid(row=0, column=0)
def Ftest2(self):
self.test1.grid_forget()
self.test2 = Button(root, text='Push #2
button', bg = 'green',
width = 15,
command = self.Ftest1,
height = 10)
self.test2.grid(row=0, column=0)

if __name__== '__main__' :
Ktest()
mainloop()

Maybe someone else has an idea about not
defining a variable.

My question is how does a budket of wires and
screws know its a bucket of wires and screws
unless someone tells it that it's a bucket of
wires and screws?

jim-on-linux

http://.www.inqvista.com
>


On Tuesday 07 November 2006 09:35,

gm********@gmail.com wrote:
Hi all,

I'm trying to write a GUI that will put up
multiple widgets in succession. My problem is
that each widget also contains the previous
widgets when they pop up. How do I
reinitialize the widget each time so that it
doesn't contain earlier ones? Actually,
another question I have is, is there a way to
set python so that it will assume any
undefined variable is 0 or ''? That is, I
have several statements like "If k 0 then
so and so" and I would like it to assume k=0
unless I tell it otherwise. I've just been
defining k=0 at the start of the program but
it seems there should be a better way.

Greg
Nov 8 '06 #5

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

Similar topics

3
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...
2
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....
7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
2
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I...
1
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...
1
by: jkuo22 | last post by:
Hi everyone, Here is my simple Tkinter script: ## start of entry.py from Tkinter import * root=Tk() e1=Entry(root, width=16) e1.pack() e2=Entry(root, width=16)
1
by: mohan | last post by:
Hello Guys, I am a beginner with Python programming and would like to implement some GUI functionalities along with my main work. So I was trying to implement one basic program (available from...
0
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.