python - Tkinter GUI problems -
im working on github project not going well.
code:
from tkinter import * def newfile(): new = label(root, text="about \n") def openfile(): openf = label(root, text="about \n") def about(): = label(root, text="about \n") root = tk() menu = menu(root) root.config(menu=menu) filemenu = menu(menu) menu.add_cascade(label="file", menu=filemenu) filemenu.add_command(label="new", command=newfile) filemenu.add_command(label="open...", command=openfile) filemenu.add_separator() filemenu.add_command(label="exit", command=root.quit) helpmenu = menu(menu) menu.add_cascade(label="help", menu=helpmenu) helpmenu.add_command(label="about...", command=about) body = label(root, text="") mainloop()
doesnt work how need it.
suposed write certant messages when click file > new
, file > open
, help > about
.
it nothing
how can make i want?
from tkinter import * root = tk() menu = menu(root) root.config(menu=menu) filemenu = menu(menu) my_label = label(root, text="select menu") my_label.place(x=10,y=10) def my_command(query): my_label.config(text=query) menu.add_cascade(label="file", menu=filemenu) filemenu.add_command(label="new", command=lambda x = "new":my_command(x)) filemenu.add_command(label="open...", command=lambda x = "open...":my_command(x)) filemenu.add_separator() filemenu.add_command(label="exit", command=root.destroy) helpmenu = menu(menu) menu.add_cascade(label="help", menu=helpmenu) helpmenu.add_command(label="about...", command=lambda x = "about...":my_command(x)) body = label(root, text="") mainloop()
@lafexlos correct. can use python types(list,dict,var , more...) on gui
design, important point how manage gui elements
, need accessible status.
don't destroy
gui element, change , reuse it.
don't include external command mainloop
(like:file,network, etc.)
all gui application required 3 critical section : init >> build >> run
otherwise got lot painful.
use gui elements text
variable
, of-course if element accesible !
i hope helpful , accept @lafexlos answer not ! code work on python2.7
Comments
Post a Comment