September 15th, 2005, 01:58 PM
Non-Standard Dialogs with Tkinter
I've explored the options of the standard dialogs (tkMessageBox, tkSimpleDialog, etc) that come with the Tkinter module, but I was wondering how one would go about creating their own. For example, in the program I'm writting, the user will enter a series of integers which defines a specific action. Then, a dialog will need to open displaying different options to the user based on their input. The user clicks one or more buttons on that dialog followed by the close button and now the program has all the necessary information to process the test and return the results.
However, I can't figure out how to create the dialog. I created a second module that when run with test data creates a window the way I want it to. However, when I import that module into a second one and the instantiate the dialog, all of the interface widgets are added to the bottom of the original window instead of opening a new one.
September 15th, 2005, 04:31 PM
Why not just use the Toplevel class and modify the widgets in this window accordingly?
September 16th, 2005, 05:49 AM
Here is one way - This example just uses a normal function to hold all the bits but you can also create new dialog sub-class which would handle the focus for you.
device_mode = ["On","Off","Automatic","Manual"]
win = Tkinter.Toplevel(parent)
mode = Tkinter.IntVar(win)
entryvalue = Tkinter.StringVar(win)
Tkinter.Label(win,text='Radio Buttons').grid(row=0,column=1,columnspan=2,sticky =Tkinter.W)
for n in range(4):
Tkinter.Label(win,text="Enter Value").grid(row=6,column = 0)
Tkinter.Entry(win,textvariable = entryvalue).grid(row=6,column = 1)
Tkinter.Button(win,text="OK",command = win.destroy).grid(row=7,column = 1)
mode = 3
level = 0.1
main = Tkinter.Tk()
demoreturn = demodialog(main,mode,level)
September 16th, 2005, 12:05 PM
I'm afraid I don't understand what you mean. Can you elaborate? I was under the impression that if you altred the toplevel class to modify the widgets, the new widgets would appear in the original window. I would prefer a new window (modal dialog) with new widgets that could process user input and return that information back to the original window.
Originally Posted by †Yegg†
September 16th, 2005, 02:20 PM
Answered my own question.
However, I've a new one: So, this new dialog is going to have 5 or 7 buttons (depending on what input the user provided to configure the dialog). Each button will perform the same action but on different values maintained in StringVar variables. What I need to do is bind the same callback function to all of the buttons, but then that callback function needs to know which button was clicked. Any ideas?
September 16th, 2005, 06:26 PM
Oh. I did not know you wanted modal. I always prefer non-modal.
Originally Posted by dgoldfdr
September 17th, 2005, 12:25 PM
1: Each button has its own callback which calls a common function but passing a constant unique to the button.
Originally Posted by dgoldfdr
2. Variation on 1 - use lambda functions in each widget definition.