Tkinter menu crash
Terry Reedy
tjreedy at udel.edu
Tue Aug 5 17:43:08 EDT 2014
On 8/5/2014 8:15 AM, Nicholas Cannon wrote:
> Ok so the first part of the program(until the start of the menu) worked fine. It ran and did what I wanted it to do.
What x.y.z version of Python. How did you run it, exactly?
> I wanted to then implement a new menu(for practise) and then it crashes. Don't know why but it just crashes.
If you ran from Idle editor on Windows, start Idle with 'python -m
idlelib' in Command Prompt to see tk error messages.
However, when I pasted code into 3.4.1 Idle Editor, changed first two
lines to
from tkinter import *
from tkinter import messagebox as tm
and ran -- no crash, no error message, no menu. I entered text into box,
clicked Submit text, and OK on popup, and nothing happens.
See below for why no menu.
When you ask about a problem, please reduce code to the minimum that
exhibits the problem for you.
> (also tips on the code will be appreciated and I gave just started Tkinter programming)
A different issue.
> Here is the code:
>
>
> from Tkinter import *
> import tkMessageBox as tm
>
> def submit():
> #message box with yes no
> tm.askyesno(title='Submit Text', message='Are you sure....')
>
> def info():
> tm.showinfo(title='About', message='Just a test Tkinter UI sample')
>
> #getting the text from the entrybox and
> #packs it into a label
> mtext = text.get()
> label1 = Label(app, text=mtext)
> label1.pack()
>
> #root window setup
> root = Tk()
> root.geometry('480x480+200+200')
> root.title('Basic Tk UI')
>
> #frame set up
> app = Frame(root)
> app.pack()
>
> #variable and entry box set up
> text = StringVar()
> entry = Entry(app, textvariable=text)
> entry.pack()
>
> #button set up
> button1 = Button(app, text='Submit text', command= submit)
> button1.pack()
>
> #menu construction
> menubar = Menu(root)
>
> filemenu = Menu(menubar)
> filemenu.add_command(label='About', command= info)
> filemenu.add_command(label='Quit', command= root.destroy)
> filemenu.add_cascade(label='TK UI Sample', menu=filemenu)
Adding filemenu as a submenu of filemenu leads to infinite loop regress.
On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an
earlier version of Python and tcl/tk.
Since menubar is left empty, it is not displayed. Fix both problems with
menubar.add_cascade(label='TK UI Sample', menu=filemenu)
> root.config(menu=menubar)
>
>
>
> #loop to listen for events
> root.mainloop()
>
--
Terry Jan Reedy
More information about the Python-list
mailing list