473,700 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter Dialog Management problems:

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?

2) Pressing the Done button in the Settings Panel, just erases the Done
button
(and any other widgets in the Panel). It does not dismiss the Panel.
Pressing
the X button does work. What callback is that? Can I make the Done button
call
that instead? How?

3) Pressing the Done button from the Main Panel has no effect? Why not? It
used
to work (self.quit()). Again, I would like to call whatever is called
when the
X button (top Right corner) is pressed.

Thanks in advance:

"""
TkInter Test
"""

#********** Imports *************** *************** ***************

import os
import sys
import Tkinter
from Tkinter import Tk, Frame, Button, Label, Entry, Scrollbar
from Tkinter import Text, Checkbutton, IntVar
import tkFileDialog
from tkMessageBox import askyesno, showerror
# ******* runScript() *************** *************** *******
def runScript (strFilename):
""" Executes Python script file """
if (VERBOSE):
print strFilename, "is being imported"
fileText = ""
try:
fptr = open (strFilename, 'r')
fileText = fptr.read()
fptr.close()
except Exception, (errno):
print "Exception in import of file:", strFilename, "- Errno = ",
errno
print (sys.exc_info() )
showerror ('Error', 'Problem importing file - see console for
details')
else:
fname = [strFilename[:-3].split('/')[-1]]
for f in fname:
__import__(f)
# ******* getGUIFilename *************** *************** *************
def getGUIFilename( ):
"""
returns a tkInter File Selection Dialog
"""
strFilename = tkFileDialog.as kopenfilename(i nitialdir='.',
filetypes=[('Python
files','*.py'),
('All Files','*.*')])
return strFilename

# ******* ScenarioPlayerD ialog class *************** *************** *******
class ScriptDialog(Fr ame):
""" Script Dialog GUI class """
def __init__(self, parent=None):
""" Script GUI class constructor """
Frame.__init__( self, parent)
self.pack()

self.commandRow = Frame(self)
self.commandLab el = Label(self.comm andRow, width=14,
text="Python Command:")
self.commandEnt = Entry(self.comm andRow)
self.commandRow .pack(side=Tkin ter.TOP, fill=Tkinter.X)
self.commandLab el.pack(side=Tk inter.LEFT)
self.commandEnt .pack(side=Tkin ter.RIGHT, expand=Tkinter. YES,
fill=Tkinter.X)
self.commandEnt .delete('0', Tkinter.END)
self.commandEnt .pack(side=Tkin ter.TOP, fill=Tkinter.X)

buttonRow3 = Frame(self)
doneBtn = Button(buttonRo w3, text='Done', command=self.do ne)
doneBtn.pack(si de=Tkinter.RIGH T)
buttonRow3.pack (side=Tkinter.B OTTOM, expand=Tkinter. YES,
fill=Tkinter.X)
buttonRow2 = Frame(self)
runBtn = Button(buttonRo w2, text='Run Script',
command=self.pl ayScript)
runBtn.pack(sid e=Tkinter.LEFT)
buttonRow2.pack (side=Tkinter.B OTTOM, expand=Tkinter. YES,
fill=Tkinter.X)
buttonRow1 = Frame(self)
executeBtn = Button(buttonRo w1, text='Execute Command')
executeBtn.pack (side=Tkinter.L EFT)
settingsBtn = Button(buttonRo w1, text='Settings. ..',
command=self.ed itSettings)
settingsBtn.pac k(side=Tkinter. LEFT)
self.verbose = Tkinter.IntVar( )
Checkbutton(sel f,text="Verbose ",variable=self .verbose,
command=self.se tVerbosity).pac k(side=Tkinter. RIGHT)
buttonRow1.pack (side=Tkinter.B OTTOM, expand=Tkinter. YES,
fill=Tkinter.X)
self.pack(expan d=Tkinter.YES, fill=Tkinter.BO TH)
self.theParent = parent
def setVerbosity(se lf):
""" Callback called when the 'Verbose' RadioButton is pressed """
global VERBOSE
VERBOSE = self.verbose.ge t()
def playScript(self ):
""" Callback called when the 'Run Script' button is pressed """
sFilename = getGUIFilename( )
if (VERBOSE):
print "Running script file: ", sFilename
runScript (sFilename)
def editScript(self ):
""" Callback called when the 'Edit Script' button is pressed """
sFilename = getGUIFilename( )
editScript (sFilename)
def executeCommand( self):
""" Callback called when the 'Execute Command' button is pressed """
strCommand = self.commandEnt .get()
if (VERBOSE):
print strCommand, "is being executed"
exec (strCommand)
def editSettings(se lf):
""" Callback called when the 'Edit Settings' button is pressed """
win = Tkinter.Topleve l()
settingsDlg = SettingsDialog (win)
def done(self):
""" Callback called when the 'Done' button is pressed """
self.quit()

# ******** start() *************** *************** *************** ***
def start():
"""
Start the Script Dialog GUI
"""
rootWindow = Tkinter.Tk()
rootWindow.titl e('Script Player - Version L1.0')
ScriptDialog (rootWindow)
rootWindow.main loop()

# ******* SocketSettingsD ialog class *************** *************** ***
class SettingsDialog( Frame):
""" Setttings Dialog GUI class """
def __init__(self, parent=None):
""" Settings Dialog GUI class constructor """
Frame.__init__( self, parent)
self.pack()
buttonRow2 = Frame(self)
self.theWidget = self
doneBtn = Button(buttonRo w2, text='Done', command=self.de stroy)
doneBtn.pack(si de=Tkinter.RIGH T)
buttonRow2.pack (side=Tkinter.T OP, expand=Tkinter. YES,
fill=Tkinter.X)
self.pack(expan d=Tkinter.YES, fill=Tkinter.BO TH)
def done(self):
""" Callback called when the 'Done' button is pressed """
self.destroy()

start()

May 18 '06 #1
1 3596
On Thu, 18 May 2006 08:41:20 -0400, Michael Yanowitz
<m.********@kea rfott.com> wrote:
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?
In fact, the two windows you created are not dialogs; they're just
windows. To turn a window into an actual "dialog", i.e basically to make
it modal, you have to do the following operations (supposing your dialog
window is named dlg and your main window in named root):

## Ensure only window can receive user events
dlg.grab_set()
## Force Dialog to stay on top of main window
dlg.transient(r oot)
## Wait for dialog to be destroyed
root.wait_windo w(dlg)
2) Pressing the Done button in the Settings Panel, just erases the Done
button
(and any other widgets in the Panel). It does not dismiss the Panel.
Pressing
the X button does work. What callback is that? Can I make the Done
button
call
that instead? How?
This is not the way it works. In fact, what you did wrong is something
that has been around for years in some Tkinter tutorial(s): you made your
classes inherit from Frame. This is a Bad Idea: a Frame is not a window,
but only a generic container. There are 2 classes for windows: Tk for the
main window and Toplevel for all others. They both also act as containers,
so you can do in them everything you do in Frames. So make your
ScriptDialog inherit from Tk, your SettingsDialog inherit from Toplevel,
remove all explicit creations of Tkinter.Tk or Tkinter.Topleve l and
instantiate your classes instead. Then calling destroy on either on the
dialogs will actually close the window.
3) Pressing the Done button from the Main Panel has no effect? Why not?
It
used
to work (self.quit()). Again, I would like to call whatever is called
when the
X button (top Right corner) is pressed.


This should work. BTW, your "done" method is not needed: creating the
Button with command=self.qu it works without problem.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
May 18 '06 #2

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

Similar topics

1
5895
by: Thomas Nücker | last post by:
Hi! I am creating a dialog-box within my application, using tkinter. The problem is the following: After the dialogbox is started, the main application window comes again to top and the dialogbox is covered by the window of the main application and must be "fetched" again via the taskbar to continue. Is there a way to "force" the dialogbox on top of all other windows? (I'm using MSWindows and Python22) The source of my dialogbox-class...
3
3337
by: DoubleM | last post by:
Hi, I'm running Python2.3.3c1 on Mandrake 9.1 The following code is designed to bring up a window with a button labeled "popup". Clicking on the popup buttons triggers a secondary window with a button labeled "ok". The second window is supposed to be modal - it should not be possible to reset the focus back to the first window or close the first window without first closing the second. The program works just fine in Windows XP...
2
4631
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in turn the contents of the 3rd list (call it states would be updated by a change in the 2nd list. If anyone can share a recipe or some ideas, I'd be grateful! Here's some sample code that displays three OptionMenus, but doesn't update the list...
0
2130
by: Stewart Midwinter | last post by:
I've got a Tkinter app that draws three histograms. At this point I am simulating real data by drawing rectangles whose size is defined by random numbers; in the future there would be real data coming from a server. I want to redraw the rectangles every time I press the Again button. This works for me, but I get an extra set of rectangles each time I press the Again button. How to get rid of this effect? Here's the app so you can see...
5
7871
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some part of my application already in focus on a system level to make this work. If for example I am entering text at the command line and call a force_focus on my root window the call will not return till I click on a window in my application. The...
3
3607
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it yesterday), so I am sure I am overlooking something simple. The basic idea is that my application will consist of a series of modal dialogs, that are chained together in "wizard" fashion. There will be some processing in between dialogs, but for the most...
5
3539
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: Current entry Company : entered co. name First entry : entered stuff The second entry: more entered stuff
6
13909
by: marcoberi | last post by:
Hi everybody. I have this code snippet that shows a window without a titlebar (using overrideredirect) and two buttons on it: one quits and the other one brings up a simple tkMessageBox. On Windows (any flavour) the tkMessagebox brings up over the underlying window. On Linux (apparently any flavour) the tkMessagebox brings up under the underlying window. You can drag the popup window near the main window to discover if it's
44
4989
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
8709
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
9202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9058
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...
0
8909
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
7791
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...
1
6555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5894
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();...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.