473,725 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help - Tkinter not doing anything

Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?

I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
Jun 27 '08 #1
7 3277
Try adding:

from Tkinter import *

at the beginning, and you don't need "var" in front of root=Tk(), just
"root = Tk()" (<-without the quotes of course)
What OS are you on? Are you running "python testapp.py" or similar to
make it run?

-Chuckk

On Sun, May 4, 2008 at 12:39 PM, Protected <pr*******@mysh elter.netwrote:
Good thinking. It was indented with spaces, so I replaced them with tabs.
Now I'm getting a SyntaxError: invalid syntax in root = Tk(). If I split the
code in two parts (with the second one beginning in that line) and run them
separately, I get no errors, but still nothing happens.

class Application(Fra me):
def say_hi(self):
print "hi there, everyone!"

def createWidgets(s elf):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit

self.QUIT.pack( {"side": "left"})

self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.say_hi

self.hi_there.p ack({"side": "left"})

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

var root = Tk()
app = Application(mas ter=root)
app.mainloop()
root.destroy()

On Sun, May 4, 2008 at 12:33 PM, Q4 <q4@invalid.com wrote:
On Sun, 4 May 2008 02:23:37 -0700 (PDT), Protected <my*******@gmai l.com>
wrote:
Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?
>
I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
--
http://mail.python.org/mailman/listinfo/python-list
If you just copy the code from the python doc the indentation might be
broken.
Send the code and I'll take a look at it.

Do you get any errors?

--
My website:
http://www.riddergarn.dk/koder/


--
http://mail.python.org/mailman/listinfo/python-list


--
http://www.badmuthahubbard.com
Jun 27 '08 #2
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.

On May 4, 11:04 am, "Chuckk Hubbard" <badmuthahubb.. .@gmail.com>
wrote:
Try adding:

from Tkinter import *

at the beginning, and you don't need "var" in front of root=Tk(), just
"root = Tk()" (<-without the quotes of course)
What OS are you on? Are you running "python testapp.py" or similar to
make it run?

-Chuckk

On Sun, May 4, 2008 at 12:39 PM, Protected <protec...@mysh elter.netwrote:
Good thinking. It was indented with spaces, so I replaced them with tabs.
Now I'm getting a SyntaxError: invalid syntax in root = Tk(). If I split the
code in two parts (with the second one beginning in that line) and run them
separately, I get no errors, but still nothing happens.
class Application(Fra me):
def say_hi(self):
print "hi there, everyone!"
def createWidgets(s elf):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack( {"side": "left"})
self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.say_hi
self.hi_there.p ack({"side": "left"})
def __init__(self, master=None):
Frame.__init__( self, master)
self.pack()
self.createWidg ets()
var root = Tk()
app = Application(mas ter=root)
app.mainloop()
root.destroy()
On Sun, May 4, 2008 at 12:33 PM, Q4 <q...@invalid.c omwrote:
On Sun, 4 May 2008 02:23:37 -0700 (PDT), Protected <myshel...@gmai l.com>
wrote:
Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?
I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
--
http://mail.python.org/mailman/listinfo/python-list
If you just copy the code from the python doc the indentation might be
broken.
Send the code and I'll take a look at it.
Do you get any errors?
--
My website:
http://www.riddergarn.dk/koder/
--
http://mail.python.org/mailman/listinfo/python-list

--http://www.badmuthahub bard.com
Jun 27 '08 #3
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.
Jun 27 '08 #4
On May 4, 12:18 pm, s0s...@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.

Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.
Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)
Jun 27 '08 #5
WxWidgets, Tkinter, PyQT are all cross platform. Also have a look at
http://wiki.python.org/moin/GuiProgramming
for more GUI frameworks.

RCB
>On May 4, 4:59*am, Protected <myshel...@gmai l.comwrote:
On May 4, 12:18 pm, s0s...@gmail.co m wrote:


On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.

Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)- Hide quoted text -

- Show quoted text -
Jun 27 '08 #6
s0****@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
>.... I'm pasting the code in IDLE and using Windows XP....

Tkinter doesn't work if you type the statements in IDLE.... it doesn't
work because IDLE is itself a Tkinter app.
Actually, _because_ IDLE is a Tkinter app,you can use it to
experiment with Tkinter in a very useful way. The trick is that
you need to start idle with the "-n" (No subprocesses) switch.
This is so useful that I build a shortcut on my desktop to do exactly
this. Using this shortcut you can see the effect of each action as
you type it, giving you an idea of exactly what must happen.

I'm assuming you are using Python 2.5 here (other versions have
related recipes, but slightly more complicated).
Right click on the desktop, and choose "New Shortcut."

For "Choose the location of the item", browse to (or type in)
C:\Python25\pyt honw.exe
Then (after your next) pick a name for your shortcut.
Right click on the resulting shortcut, and go to "properties "
Change the "Target" entry from:
C:\Python25\pyt honw.exe
to:
C:\Python25\pyt honw.exe -m idlelib.idle -n
Also, if you are like me, you'll want to change the "Start in" directory
to wherever you work on python code --so imports of your own stuff "just
work", and so "File open'" and "Save As" default to a "nice" directory.

The Idle you get with this "corrupts" more easily, since the "-n" says
"no subprocess." Things like restarting the shell don't work. _But_
Tkinter stuff is available (there is already a running mainloop). You
can interactively do simple things a step at a time and watch the
results. It is a _great_ way to experiment with Tkinter.
--Scott David Daniels
Sc***********@A cm.Org

Jun 27 '08 #7
On May 4, 6:59 am, Protected <myshel...@gmai l.comwrote:
On May 4, 12:18 pm, s0s...@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.

Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)
Of course. I forgot to say about that. It is cross platform, like most
things in Python. I'd say it's actually more cross platform than
Tkinter, because of the looks of both in different platforms. In
Tkinter, you can get all the widgets to work in all the platforms it
supports, but the widgets look so different on different platforms,
that at the end you end up modifying the code anyway so that the
controls look better on the platform that you port the program to.
With what I've done with wxPython, the controls look great on any of
the platforms I've tried my programs in. Another thing: wxPython is a
port of the wxWidgets toolkit which is for C++. It has also been
ported to a bunch of other languages like Ruby, Perl, C#, etc; so if
you learn any of the languages which wxWidgets has been ported to, you
can use the toolkit in the same way that you've been doing with
Python, except that with the syntax of the other language.
Jun 27 '08 #8

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

Similar topics

5
7199
by: Andrew Gregory | last post by:
Could someone help me out with these few lines of code: I would like to know why the Quit button in this application removes the buttons and causes "Quitting" to be printed, but does not close the outer frame. Andrew. # Demonstration TK interface Windows application # Runs ok from within IDLE
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:
5
4763
by: carljohan.rehn | last post by:
I would like like to start doing some GUI-programming in Python, but don't know which library to choose. Tkinter seems a bit old. Correct me if I am wrong! The layout doesn't look as nice as for the others. wxPython seems to be the first-hand choice for people doing W32-programming (with MFC-experience). PyGtk seems to be a modern, very clean and nice approach, but with poor
5
2060
by: max(01)* | last post by:
hello. the following code: 1 from Tkinter import * 2 3 class MiaApp: 4 def __init__(self, genitore): 5 self.mioGenitore = genitore 6 self.i = IntVar()
6
8252
by: Richard Lewis | last post by:
Hi there, I've got a tree control in Tkinter (using the ESRF Tree module) but I can't get it to layout how I want it. I'd like to have it so that it streches north/south (anchored to the top and bottom), is of a fixed width and is anchored to the left hand side. Here's my code (its derived from one of the examples from the ESRF web site):
5
3561
by: Ben Kovitz | last post by:
Hi, I just tried to run Tkinter on OS X 10.3.9 under Python 2.4.3, and I'm getting a bus error as soon as I call Tk(). Googling has turned up info other Tkinter bus errors, but not this one that occurs right away, before doing anything fancy. Tk/Tcl is definitely installed on my computer, as verified by running "wish" and seeing the window come up. "info patchlevel" returns 8.4.5. Here's the tail of the output from python -v:
4
2107
by: Chris | last post by:
Hi, I'm puzzled by some strange behavior when my Python/Tkinter application quits (on linux): the terminal from which I started Python is messed up. If start up python, then import the code below, then start the program with Application(), then click the Quit button, my terminal never prints anything again (such as commands I type).
44
4996
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
1543
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
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
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8099
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...
0
6011
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();...
1
3228
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
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.