Forums

tkinter

hi guys. Noobie here! My code is not working for whatever reason. I noticed when I comment the DropDown list (from "For Incident Type" section) commands, the window comes up but when I uncomment, the code runs but no window pops up.. Any ideas why?? Also, how do you update the Status bar when you click a button, something like "You clicked button X"? Or how do you make different section (like in Word for word and character count? and how to update one section when hovering over with the mouse? Much appreciated for your help!! Code below:

root = Tk()

##### Create main menu ###########

mainmenu = Menu(root) root.config(menu = mainmenu) submenu = Menu(mainmenu)

mainmenu.add_cascade(label = "File", menu=submenu)
submenu.add_command(label = "New Project", command=doNothing)
submenu.add_separator() submenu.add_command(label = "Exit", command= exitfunc)

editmenu = Menu(mainmenu) mainmenu.add_cascade(label = "Edit", menu=editmenu) editmenu.add_command(label = "Redo", command = doNothing)

##### Toolbar

toolbar = Frame(root, bg="blue")
insertButt = Button(toolbar, text = "Insert image", command = InsertImgcmd)
insertButt.pack(side=LEFT, padx = 2, pady=2)
printButt = Button(toolbar, text="Print", command = doNothing) printButt.pack(side=LEFT, padx = 2, pady=2)

toolbar.pack(side=TOP, fill=X)

##### Creating variables

var = StringVar()

##### Create Dropdown list for Incident Type

LabelTypeDDL = Label(root, text="Type").grid(row=2, column=1, sticky=W)

TypeDDL = OptionMenu(root, var, NORMAL, PARENT, CHILD, FLWALK)

TypeDDL.configure(font=("Calibri", 15))

TypeDDL.grid(row=5, column=0)

#### Statusbar

statusbar = Label(root, text=statusmessage, bd=1, relief=SUNKEN, anchor=W)
statusbar.pack(side=BOTTOM, fill=X)

root.title("Summary Tool") root.geometry("300x200") root.mainloop()

Where would the window pop up? There is no screen on our servers for you window to pop up on.

Not sure I understand your question? but if I comment the ####Create Dropdown list for Incident Type#### section, the window (root) pops up on my screen... Furthermore, if I copy that section onto a different file, the root window is created as normal. but when I put the code within the main code, nothing displays on my screen..

There is no place for the pop up to be drawn, so it will not be drawn. tkinter cannot work on PythonAnywhere because there is no screen for the UI to be shown on.

I am running this on my python installation on a desktop. I have a screen. It works if I use the below on a different file, I just don't understand why it doesn't work when incorporate on longer code..

from Tkinter import *

root = Tk()

var = StringVar()
###########  Create Incident Types  Dictionary###########
TypeD = dict(Normal='NORMAL', \
             Parent='PARENT', \
             Child='CHILD', \
             Floor_Walk='FLWALK')
TypeNameL = list()
for i in TypeD.keys():
    TypeNameL.append(i)                                         #Convert the TypeD Dictionary keys into a list
selectedType = StringVar()
selectedType.set('Choose the appropriate Incident Type')

##### Create Dropdown list for Incident Type
LabelTypeDDL = Label(root, text="Type").grid(row=2, column=1, sticky=W)
TypeDDL = OptionMenu(root, var, *TypeNameL)
TypeDDL.configure(font=("Calibri", 15))
TypeDDL.grid(row=5, column=0)

root.title("Summary Tool")
root.geometry("300x200")
root.mainloop()

[edit by admin: formating]

Ah, I see. These are the forums for PythonAnywhere, a server-based hosting environment. For general Python questions about running it on your own machine, a better place to ask would be Stack Overflow.

I resolved it: I can't have .grid() and .pack in the same object :) I need to choose one.

Thanks for your help anyway!!