Hi, I'm using the "Learning to Program" GUI tutorial on http://www.freenetpages.co.uk/hp/alan.gauld/
and am trying to write my first GUI. However, the code the tutorial
gives for starting by making a window:
import Tkinter
top = Tkinter.Tk()
dir(top)
Does not work. The Python interpreter does not complain about anything,
but the window the tutorial promises will apperar will not. I'm using
Python 2.4.2 and the Eric 3.7.0 IDE on Ubuntu 5.10. Anybody know what
to do?
-- /usr/bin/byte 12 1227
Byte wrote: Hi, I'm using the "Learning to Program" GUI tutorial on http://www.freenetpages.co.uk/hp/alan.gauld/ and am trying to write my first GUI. However, the code the tutorial gives for starting by making a window:
import Tkinter
top = Tkinter.Tk()
dir(top)
Does not work. The Python interpreter does not complain about anything, but the window the tutorial promises will apperar will not. I'm using Python 2.4.2 and the Eric 3.7.0 IDE on Ubuntu 5.10. Anybody know what to do?
You have to call top.mainloop() for it work. What is dir(), btw? Is it a
class for creating the application?
John Salerno wrote: What is dir(), btw? Is it a class for creating the application?
Heh heh, how quickly I forget about built-ins. :) Try something like this:
import Tkinter as tk
root = tk.Tk()
label = tk.Label(root, text='Hello world!')
label.pack()
root.mainloop()
On 6/5/06, John Salerno <jo******@nospamgmail.com> wrote: What is dir(), btw? Is it a class for creating the application?
[Bernard] In your Python documentation, dir() is described in the
built-in functions (section 2.1) as well as the tutorial, in the
"Modules" section (chapter 6). Unless you were being sarcastic? ;-)
Bernard
Bernard Lebel wrote: Unless you were being sarcastic? ;-)
Just temporarily dense. :)
Thanks, this works. Now, since the tutorial I was using is clearly
rubbish, any better ones? For a (relative) newbie please. Also, how do
I code a GUI Hello World program?
-- /usr/bin/byte
Byte wrote: Thanks, this works. Now, since the tutorial I was using is clearly rubbish, any better ones? For a (relative) newbie please. Also, how do I code a GUI Hello World program?
-- /usr/bin/byte
Actually, that site is generally considered to be a pretty good place to
start for tutorials. I think maybe you didn't go far enough through the
"Tour of Some Common Widgets" section before you experienced problems
(i.e., you didn't get to pack() or mainloop(), etc.).
But I will agree with you that it is confusing when it says, following
the top = Tk() line, "Notice that a new blank window has appeared",
because as you noticed, nothing appears yet. My only guess is that this
is either a mistake, or the tutorial is a little old, because I think
Tkinter used to behave differently in the interactive prompt than it
does now.
Anyhow, I would stick with that site, but you might also try Fredrik's
tutorial: http://www.pythonware.com/library/tkinter/introduction/
It's a great little intro, but also a reference to the widgets, methods,
etc. I pretty much learned everything so far from that site (admittedly
I'm just as new as you are, but it's still a good site!) :)
Byte wrote: Also, how do I code a GUI Hello World program?
P.S. The link I supplied begins with two versions of a Hello World app.
Byte wrote: Thanks, this works. Now, since the tutorial I was using is clearly rubbish, any better ones? For a (relative) newbie please. Also, how do I code a GUI Hello World program?
-- /usr/bin/byte
How does John Salerno previous code NOT fit the bill? John Salerno wrote: ... import Tkinter as tk
root = tk.Tk() label = tk.Label(root, text='Hello world!') label.pack() root.mainloop() ...
I think you should get a copy of "an-introduction-to-tkinter" from
Fredrik Lundh and try out the different usage examples and experiment,
then post more specific questions (after searching this newsgroup since
many questions lie here already answered).
On Wed, 07 Jun 2006 17:38:39 GMT, John Salerno <jo******@NOSPAMgmail.com>
wrote:
[snip] But I will agree with you that it is confusing when it says, following the top = Tk() line, "Notice that a new blank window has appeared", because as you noticed, nothing appears yet. My only guess is that this is either a mistake, or the tutorial is a little old, because I think Tkinter used to behave differently in the interactive prompt than it does now.
It may be a platform-specific issue: On Unix/Linux, a window *does* appear
when you instantiate Tk, at least with tcl/tk 8.3 and 8.4 (which is the
latest stable version AFAIK).
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Eric Brunel wrote: It may be a platform-specific issue: On Unix/Linux, a window *does* appear when you instantiate Tk, at least with tcl/tk 8.3 and 8.4 (which is the latest stable version AFAIK).
same on Windows, but it often appears *beneath* the window you're typing
into, so you have to look for it in the task bar.
this also relies on Python being able to keep the Tkinter event loop
going behind the scenes; different command-line implementations have
different limitations.
for example, on Windows, the event loop runs only when you're at an
empty Python prompt; as soon as you start typing the next command, the
interpreter switches over to "text input mode", and the event loop is
paused until you press return.
</F>
Fredrik Lundh wrote: Eric Brunel wrote:
It may be a platform-specific issue: On Unix/Linux, a window *does* appear when you instantiate Tk, at least with tcl/tk 8.3 and 8.4 (which is the latest stable version AFAIK).
same on Windows, but it often appears *beneath* the window you're typing into, so you have to look for it in the task bar.
this also relies on Python being able to keep the Tkinter event loop going behind the scenes; different command-line implementations have different limitations.
for example, on Windows, the event loop runs only when you're at an empty Python prompt; as soon as you start typing the next command, the interpreter switches over to "text input mode", and the event loop is paused until you press return.
</F>
I thought it might be something like that. A window doesn't appear for
me at all, but it may be because I haven't updated Tkinter since
installing Python, so maybe it's a little older.
John Salerno wrote: <Next from Fredrik Lundh> <Quoting Eric Brunel> It may be a platform-specific issue: On Unix/Linux, a window *does* appear when you instantiate Tk, at least with tcl/tk 8.3 and 8.4 (which is the latest stable version AFAIK).
Here you should have chimed in with your OS and Python versions.
same on Windows, but it often appears *beneath* the window you're typing into, so you have to look for it in the task bar.
this also relies on Python being able to keep the Tkinter event loop going behind the scenes; different command-line implementations have different limitations.
for example, on Windows, the event loop runs only when you're at an empty Python prompt; as soon as you start typing the next command, the interpreter switches over to "text input mode", and the event loop is paused until you press return.
I thought it might be something like that. A window doesn't appear for me at all, but it may be because I haven't updated Tkinter since installing Python, so maybe it's a little older.
When running on Windows 2000 (at least), with Python 2.3 or greater,
Idle now (by default) stays more separate from the process running the
user's code. As a result, debugging and namespaces are more stable, but
the users space doesn't have a display loop running. To help out in
cases like this, Idle has the "-n" switch which means roughly "no
subprocess." If you are on windows (I have no idea what system you are
running on), you can create a shortcut like I have (I call it Py24One).
I just copied the Idle shortcut, and changed the "target"
from:
C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.pyw
to:
C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.pyw -n
That "target", by the way, can also be typed directly to the command
line to start Idle in "no subprocess" mode.
The big advantage to using Idle this way is that (because Idle is
already running a display loop), you can see the effects of your
commands immediately. So the comments in your intro will hold true.
--Scott David Daniels sc***********@acm.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike |
last post by:
I am sure that I am making a simple boneheaded mistake and I would
appreciate your help in spotting in. I have just installed
apache_2.0.53-win32-x86-no_ssl.exe
php-5.0.3-Win32.zip...
|
by: Dave |
last post by:
I created a program using VB6 under WIN 98. The program uses an ado
database.
When I use the package and deployment program in VB6 on this program
and then install it on a machine with XP Pro on...
|
by: anuradha.k.r |
last post by:
hi,
i am writing a socket program in python,both client side and server
side.I've written the client side which is working perfectly
fine(checked it against server program written in C).but as for...
|
by: muser |
last post by:
Can anyone run this program through their compiler or if they can see
a logical error please point it out. I have my tutor working on it at
the moment but I would rather a less ambigious response...
|
by: Tom Lee |
last post by:
Hi,
I'm new to .NET 2003 compiler. When I tried to compile my
program using DEBUG mode, I got the following errors in the
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
\include\xdebug...
|
by: bbxrider |
last post by:
for win2k adv server/iis5.0
trying to run an external program from my asp routine that has multiple
parameters, see following
set shell = server.createobject("wscript.shell")
shell.Run...
|
by: Mark Rockman |
last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------
Preparing resources...
Updating references...
Performing main compilation...
error CS0583: Internal Compiler Error...
|
by: Ken |
last post by:
When running a program in the debugger, what would cause it to crash without
any error messages? I get "The program has exited with code 0 (0x0)".
The program is a MDI app with threading for...
|
by: karthikbalaguru |
last post by:
Hi,
One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |