I am currently reading An Intro to Tkinter (1999) by F. Lundh. This doc
was published in 1999 and I wonder if there is a more recent version.
I've googled a bit and this version is the one I keep finding. I like
how this document is organized and also how it provides the code with
visuals of what should appear on the screen. If there are other docs I
should read, please let me know.
Second, I am trying to work through a couple of the examples and make
some small tweaks as I go to see how new things can work. In the first
case, I have copied the code in the book to see how the menu works and
are created as in the example menu.py below. I see how menus are created
and how the command option is used to call the function callback.
# menu.py
from Tkinter import *
def callback():
print "called the callback!"
root = Tk()
# create a menu
menu = Menu(root)
root.config(men u=menu)
filemenu = Menu(menu)
menu.add_cascad e(label="File", menu=filemenu)
filemenu.add_co mmand(label="Ne w", command=harold)
filemenu.add_co mmand(label="Op en...", command=callbac k)
filemenu.add_se parator()
filemenu.add_co mmand(label="Ex it", command=callbac k)
helpmenu = Menu(menu)
menu.add_cascad e(label="Help", menu=helpmenu)
helpmenu.add_co mmand(label="Ab out...", command=callbac k)
mainloop()
However, I now want to incorporate a basic python program with a
command. Say I have a simple program called test.py
# test.py
filename = raw_input("Plea se enter the file you want to open: ")
new_file = raw_input("Save the output file as: ")
f = open(new_file, 'w')
new = open(filename, 'r')
for line in new:
x = line.split('\t' )
print >f, x[0],':', x[1]
f.close()
To make this example complete assume I have a text file like this
# data.txt
1 one
2 two
3 three
4 four
So, the user currently just follows directions on the screen, enters the
file names, and I get what I want. I'd like to try experimenting with
gui programming to see if the python programs I have written can be made
even more user friendly. I currently use py2exe to create executables so
that others in my organization can use these programs.
In that spirit, say I want to have a menu option that allows the user to
search their computer for this file, execute the python code and then
save the result as a user-defined filename. So, I guess my questions are
how do I associate the portion of code in menu.py
"filemenu.add_c ommand(label="O pen...", command=callbac k)" with an
operation that gives the user the ability to search the drives on their
machine and then once they do let python execute the code in test.py?
Many thanks, 2 2050
On Apr 16, 7:46 am, "Doran, Harold" <HDo...@air.org wrote:
I am currently reading An Intro to Tkinter (1999) by F. Lundh. This doc
was published in 1999 and I wonder if there is a more recent version.
I've googled a bit and this version is the one I keep finding. I like
how this document is organized and also how it provides the code with
visuals of what should appear on the screen. If there are other docs I
should read, please let me know.
There's some good Tkinter coverage in Lutz's tome, "Programmin g Python
3rd Ed." and it also shows how to do a search for a file across your
file system, iirc.
>
Second, I am trying to work through a couple of the examples and make
some small tweaks as I go to see how new things can work. In the first
case, I have copied the code in the book to see how the menu works and
are created as in the example menu.py below. I see how menus are created
and how the command option is used to call the function callback.
# menu.py
from Tkinter import *
def callback():
print "called the callback!"
root = Tk()
# create a menu
menu = Menu(root)
root.config(men u=menu)
filemenu = Menu(menu)
menu.add_cascad e(label="File", menu=filemenu)
filemenu.add_co mmand(label="Ne w", command=harold)
filemenu.add_co mmand(label="Op en...", command=callbac k)
filemenu.add_se parator()
filemenu.add_co mmand(label="Ex it", command=callbac k)
helpmenu = Menu(menu)
menu.add_cascad e(label="Help", menu=helpmenu)
helpmenu.add_co mmand(label="Ab out...", command=callbac k)
mainloop()
However, I now want to incorporate a basic python program with a
command. Say I have a simple program called test.py
# test.py
filename = raw_input("Plea se enter the file you want to open: ")
new_file = raw_input("Save the output file as: ")
f = open(new_file, 'w')
new = open(filename, 'r')
for line in new:
x = line.split('\t' )
print >f, x[0],':', x[1]
f.close()
To make this example complete assume I have a text file like this
# data.txt
1 one
2 two
3 three
4 four
So, the user currently just follows directions on the screen, enters the
file names, and I get what I want. I'd like to try experimenting with
gui programming to see if the python programs I have written can be made
even more user friendly. I currently use py2exe to create executables so
that others in my organization can use these programs.
In that spirit, say I want to have a menu option that allows the user to
search their computer for this file, execute the python code and then
save the result as a user-defined filename. So, I guess my questions are
how do I associate the portion of code in menu.py
"filemenu.add_c ommand(label="O pen...", command=callbac k)" with an
operation that gives the user the ability to search the drives on their
machine and then once they do let python execute the code in test.py?
Many thanks,
It sounds like you want to run code from within your own program. This
would require embedding a Python interpreter, which is quite possible,
although I do not know how to do it. I would suggest that you just use
a Tkinter-created frame/window that allows the user to enter the
information into text controls rather than a command line type
interface. You could even use a "Browse" button and let the user
search for the file using a file dialog. Check out the sample code for
such a beast in the recipe linked below: http://aspn.activestate.com/ASPN/Coo.../Recipe/438123
If you do want to go the embedding route, you'll want to read the
following information linked below: http://docs.python.org/api/embedding.html http://www.python.org/doc/ext/embedding.html http://www.ragestorm.net/tutorial?id=21 http://www.codeproject.com/KB/cpp/embedpython_1.aspx
Hope that gets you going.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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:
|
by: Ron Stephens |
last post by:
The newly rechristened Python Learning Foundation is a web site
dedicated to the assistance of people learning the Python programming
language. Features include:
1. Daily lists of new and recent Python-related web articles,
Sourceforge projects, and Vaults of Parnassus listings. These are
generated using Hans Nowak's Python web spider, mygale.py, and are
automatically updated each day. (You can visit Han's interesting blog
at <a href =...
|
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...
|
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?
| |
by: Dick Moores |
last post by:
In a couple of places recently I've seen Brent Welch's _Practical
Programming in Tcl & Tk_ (<http://tinyurl.com/ynlk8b>) recommended
for learning Tkinter well.
So a couple of questions:
1) Is it really good for learning Tkinter, even though it doesn't
mention Tkinter at all (in the 4th edition at least)?
2) If it is good for learning Tkinter, can I get by with a cheaper,
|
by: KDawg44 |
last post by:
Hi,
I am new to Python and am trying to write a little front end to
another application in Python.
What I want is to have a gui pop up listing some items with several
buttons. The guts of the program I am not having any trouble with but
the GUI part I am (or more accurately, the transition between GUI
pieces).
|
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 my pc. But, it is not getting installed and is
failing by throwing
the below errors. Should i need to configure / install any specific
files for resolving this issue ?
|
by: Edward Cormier |
last post by:
Which computer books are the best to begin learning Python 2.5 with?
I've heard that Learning Python 3rd Edition is a good choice - can
anyone give any more advice on this?
Thanks.
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |