473,396 Members | 2,085 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,396 software developers and data experts.

Using Tkinter

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
this I mean that the format would be something like this:

You have Page1 : This has 2-3 buttons on it.
Clicking on each button opens up a new window respectively having
something entirely different... possibly more buttons,text fields etc.

Problem 2:

If I have a drop down box in Pythons tkinter, is it possible that the
entities that the drop down has are items that have been picked up
from a notepad file via file handling?

Problem 3:

I have 2 radio buttons Radio button A and radio button B. Below them I
have I have 2 separate panels Panel A and Panel B possibly each having
separate text fields, buttons etc in it.

Is it possible that only one of them is shown depending on the radio
button that I have selected? Meaning that if I have selected on Radio
button A only Panel A is shown and likewise if I have selected Radio
Button B only panel B is shown.

I guess that's it for now. Even if any1 here knws any of these
problems do post back asap.
Wud b waiting for replies.
Thanks.
Aug 22 '08 #1
3 3889
For references, you may use these PDF files (One URL changed since my
last time there, but it should be correct for now):
http://www.pythonware.com/media/data...to-tkinter.pdf
http://infohost.nmt.edu/tcc/help/pub...er/tkinter.pdf
(The first one may be useful for starting out)

I'll let you know ahead of time, my knowledge is in Python 2.5 (newer
versions, as I've heard, are becoming incompatible with older versions
-- at least, version 3.0, a.k.a. Python 3000).
I'll also let you know that this may be my first time helping someone.

On Aug 22, 7:20 am, J-Burns <arslanbur...@gmail.comwrote:
Problem 1:

How do I make something appear on 2 separate windows using Tkinter? By
this I mean that the format would be something like this:

You have Page1 : This has 2-3 buttons on it.
Clicking on each button opens up a new window respectively having
something entirely different... possibly more buttons,text fields etc.
You can make a class for each that inherits from Tkinter.Toplevel or
Tkinter.Frame so you can re-create the window on the fly.
I'll code for using "import Tkinter" and not "from Tkinter import *"
and also code for using "pack()" for putting widgets on a window.
Remember that this is just a sample (it should work, but I didn't test
it).
* NEVER try to pack() one widget and grid() another in the same
"parent"
class Page1(Tkinter.Frame):
def __init__(self, parent=None):
Tkinter.Frame.__init__(self, parent)
self.make_widgets()
self.spawned_windows = {} # for holding the windows
# assumption: only one of each type of window open
# at a time
def make_widgets(self): # for putting in the widgets
self.btn1 = Tkinter.Button(self)
self.btn1["text"] = "Spawn Window 1" # or some other text
self.btn1["command"] = self.spawn_window_1
self.btn1.pack() # this alone will pack the button on the next
# available spot horizontally
# continue with the other buttons

def spawn_window_1(self): # I put a generic name here for sample
# still assuming one of each type of window open
if self.spawned_windows.has_key("window1"):
self.spawned_windows["window1"].lift() # show the window
return # already has one open
self.spawned_windows["window1"] = Page1A(self, spawn_closed,
"window1") # create
one
# if you already executed a "mainloop()" call, it should show

def spawn_closed(self, name): # a callback to say it closed
if self.spawned_windows.has_key(name):
del self.spawned_windows[name]
return True # meaning: it was found and closed
return False # meaning: it was not found

# other "def"s (functions/subroutines) here
class Page1A(Tkinter.Toplevel):
def __init__(self, master, closecmd, closearg):
Tkinter.Toplevel.__init__(self, master)
# for telling Page1 that this closed
self.closecmd = closecmd
self.closearg = closearg
self.make_widgets()

def make_widgets(self):
# *create widgets here
# now, a close button (I assume you dont need it anymore)
self.closebtn = Tkinter.Button(self)
self.closebtn["text"] = "Close window"
self.closebtn["command"] = self.destroy
self.closebtn.pack()

def destroy(self): # tell Page1 that this closed
self.closecmd(self.closearg)
Tkinter.Toplevel.destroy(self)
Problem 2:

If I have a drop down box in Pythons tkinter, is it possible that the
entities that the drop down has are items that have been picked up
from a notepad file via file handling?
You can just open the file once (on the script's start), when you
press a button, or every so often, that will update the drop-down box.
I don't know how you have that file set, so you may need to program
the syntax in.
Examples of how that file may be in:

* One item per line -- use "f = open(filename)" and
* "for line in f:
* # add line here"
* NOTE: requires to clear the drop-down before
* adding lines, and restoring the selected item
File
Edit
Help

* Comma separated with first one for drop-down label
* -- use a Python module available
* (I think "import csv" and use the Python Docs for help)
File,New,Open,Save,Quit
Edit,Cut,Copy,Paste

* Microsoft's .ini file style
* -- Should be found somewhere in the Python Documentation
[File]
name1a=value1a
name1b=value1b
[Edit]
name2a=value2a
namd2b=value2b

etc.
Problem 3:

I have 2 radio buttons Radio button A and radio button B. Below them I
have I have 2 separate panels Panel A and Panel B possibly each having
separate text fields, buttons etc in it.

Is it possible that only one of them is shown depending on the radio
button that I have selected? Meaning that if I have selected on Radio
button A only Panel A is shown and likewise if I have selected Radio
Button B only panel B is shown.
Python 2.5 and an up-to-date OS (WinXP had a problem in the past)

* Hide
widget.pack_forget() # if you used pack()
widget.grid_forget() # if you used grid()
widget.place_forget() # if you used the Unknown-To-Me place()
* Show
* just re-pack (etc.) it.
I guess that's it for now. Even if any1 here knws any of these
problems do post back asap.
Wud b waiting for replies.
I don't know if it would all work, but I tried to help out.
Thanks.
You're welcome.

Aug 22 '08 #2
J-Burns wrote:
Hello. Im a bit new to using Tkinter and im not a real pro in
programming itself... :P. Need some help here.
OK, looks like you are getting direct answers, but I thought I'd
mention an easy way to experiment with Tkinter programming.

If you start Idle with the "-n" switch (*), then anything you do shares
the same "mainloop" as Idle, and your window manipulation is "live".
This means, that immediately after typing in:
>>import Tkinter
f = Tkinter.Frame()
You will see the frame f show up. You can experiment directly with
watching the effects of calls that you make in the interactive
interpretter.

(*) Easy way to do this:
On some systems, associate a button with "pythonw -m idlelib.idle -n".
On a Windows system with an Idle shortcut/button/icon already:
Copy the shortcut/button/icon
Right-click the shortcut and select the "properties" menu.
On the "General" tab of the Properties window:
Give the shortcut a nicer name (I use Idle25-n for mine).
On the "Shortcut" tab of the properties window, add a space and a -n
to the target line.
Click OK, and try out your new button.

--Scott David Daniels
Sc***********@Acm.Org
Aug 23 '08 #3
In article <2b**********************************@b2g2000prf.g ooglegroups.com>,
<ad******@gmail.comwrote:
>On Aug 22, 7:20 am, J-Burns <arslanbur...@gmail.comwrote:
Aug 23 '08 #4

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

Similar topics

1
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...
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...
0
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...
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...
11
by: Kenneth McDonald | last post by:
Any guesses as to how many people are still using Tkinter? And can anyone direct me to good, current docs for Tkinter? Thanks, Ken
0
by: Guilherme Polo | last post by:
2008/5/10 Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net>: I will say no to the first question. Now about the second question.. there are these links you may find interesting: "An...
3
by: seanacais | last post by:
I'm trying to build an unknown number of repeating gui elements dynamically so I need to store the variables in a list of dictionaries. I understand that Scale "variable" name needs to be a...
0
by: dudeja.rajat | last post by:
Hi, I'm using Tkinter module to create a GUI application. I found that the combo box is not present in Tkinter module. It comes with Tix module. Could some one give me an example to create a...
0
by: dudeja.rajat | last post by:
On Mon, Aug 25, 2008 at 12:57 PM, <dudeja.rajat@gmail.comwrote: Ok...now I found the way to do that. But I'm stuck further. my code is as below: main module ********************** myRoot...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.