如何解决在Python-tkinter中选择后立即在框架中获取选项菜单的选择
我正在尝试将菜单中的选定选项打印到框架(显示为log_box),但是找不到在框架中显示动作的方法。我的菜单选项代码...
from tkinter import *
import tkinter as tk
# Creating window object
window = Tk()
window.title("Windows App")
window.configure(bg="#263D42")
window.geometry("700x400")
# Menubar
def DummyActions():
'''
:return: list of actions,where each action is a tuple whose first element is the new node and the second element is
the mode of transportation to be used to reach the node
'''
import random
coin_flip = random.random()
if coin_flip >= 0.5:
return [(38,'B'),(78,'T'),(108,'U')]
else:
return [(48,(58,(68,'U')]
if __name__ == '__main__' :
print('Running assignment dummy APIs')
options = []
for action in DummyActions():
options.append(action)
option = action
menubar = Menu(window)
menuOptions = options
menu = Menu(menubar,tearoff = 0)
menubar.add_cascade(label ='Menu',menu = menu)
for opt in menuOptions:
menu.add_command(label = opt,command = None)
menu.add_separator()
window.config(menu = menubar)
#Log box - Display all actions
log_box = Frame(window,bg="#f0e4ea")
log_box.place(relwidth=0.9,relheight=0.8,relx=0.05,rely=0.1)
label = Label(log_box,text="Log Box",pady=2,bg="gray")
label.pack()
window.mainloop()
任何帮助将不胜感激!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。