The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Some very basic Tkinter help
Discuss Some very basic Tkinter help in the Python Programming forum on Dev Shed. Some very basic Tkinter help Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 9th, 2003, 12:47 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
|
Some very basic Tkinter help
Hi, I've decided to finally get dirty with Tkinter. Anyway, I grabbed the following code from http://www.pythonware.com/library/t...hello-again.htm :
Code:
# File: hello2.py
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print "hi there, everyone!"
root = Tk()
app = App(root)
root.mainloop()
Nothing very complicated, that's for sure, but for some reason each time I press the QUIT button, the program goes fubar and I Ctrl-Alt-Del my way out of it. I've tried it on my own PC and our university's and both get the same result. I can't see what could be wrong with the code, so any help/corrections would be appreciated.
__________________
Time is the greatest of teachers ; sadly, it kills all of its students.
- Hector Berlioz
|

October 9th, 2003, 05:18 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
I've knowticed the same thing! Your script worked fine on windows XP, but if i took it to 98 or ME the console window would hang like a beast! I havn't tested this on *nix but i think its a TK thing since it doesn't seem to happen with other GUI kits..
Mark.
__________________
programming language development: www.netytan.com – Hula
|

October 9th, 2003, 07:36 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
|
I've had this problem before, try replaceing frame.quit with frame.destroy.
|

October 10th, 2003, 12:26 AM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
Quote: Originally posted by netytan
I havn't tested this on *nix but i think its a TK thing since it doesn't seem to happen with other GUI kits. |
I've just tried it on Linux, and it works just fine. Weird.
Baltor : I'll try that... tomorrow. I can barely type now. 
|

October 10th, 2003, 03:00 AM
|
|
Contributing User
|
|
Join Date: May 2003
Location: Norway
Posts: 41
Time spent in forums: 3 h 52 m 22 sec
Reputation Power: 10
|
|
|
WinMe/Python 2.2.3
It worked fine a few times, then it hanged, and I couldn't even kill the dos window or restart the computer via the start menu. I remember having problems earlier when I experimented with some GUI's, and this was the reason I downloaded WxPython. Haven't done anything with WxPython so I don't know if it's any better. But I suspect it is a Tk/WinME problem.
|

October 10th, 2003, 04:38 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Ok, maybe this is a windows/tk thing then guys  . its still there in 2.3 so i don't hold out much hope of it going away any time soon.. Anyone nowtice that it hangs more often when you've printed to the console window? In any case, if your doing anything more complex than messing arround with GUI's i'd really try some of the other great kits like wxWindows and QT. But i'm no TK fan though obviously so
Mark.
Last edited by netytan : October 10th, 2003 at 04:45 AM.
|

November 13th, 2003, 06:35 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I'm trying out Python too and I'm having the same problem with a Windows 98 computer.
Quote: Originally posted by Baltor
I've had this problem before, try replaceing frame.quit with frame.destroy. |
I tried that, but it still doesn't quite seem to work. The QUIT button will make the buttons disappear, but the window remains. Clicking the close button in the window closes it. I guess that's better than hanging, though.
Just to mess around, though, I tried changing it to "root.destroy." That seems to work. I'm quite new to Python, so if there's any reason that might a bad idea for some reason, please say so.
|

November 14th, 2003, 04:38 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
I think the general desision here was that destroy() is just as valid a way to close a widow as quit() and works better.. i wouldn't worry about it and its not going to make any differance to the rest of your programe
Mark.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|