fork download
  1. from tkinter import *
  2. import tkinter as tk
  3.  
  4. class MainWnd:
  5. def __init__(self,Frame):
  6. self.SelectName = StringVar()
  7. self.Names = ["aa","bb"]
  8. self.OptModuleName = OptionMenu(app,self.SelectName,*self.Names,command=self.SelectModule)
  9. self.OptModuleName.pack()
  10. self.BtnUpdate = Button(app, text="Update",command=self.Update)
  11. self.BtnUpdate.pack()
  12. def SelectModule(self,value):
  13. print("choose",value)
  14. def Update(self):
  15. print("Update Obtion Menu")
  16. self.OptModuleName['menu'].delete(0,'end')
  17. self.Names.clear()
  18. self.Names = ["cc","dd"]
  19. for Item in self.Names:
  20. self.OptModuleName['menu'].add_command(label=Item,
  21. command=tk._setit(self.SelectName, Item, self.SelectModule))
  22. app = Tk()
  23. app.geometry('300x200')
  24. MainWindows = MainWnd(app)
  25. app.mainloop()
  26.  
Runtime error #stdin #stdout #stderr 0.03s 76608KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 22, in <module>
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable