2024-05-19 12:02:57 发布
网友
我想在Tkinter中有一个下拉菜单,其中包括与此命令相关联的快捷键。这可能吗?
如何在特定字符下添加下划线,以允许Alt-F-S(文件->;保存)?
Alt-F-S
import tkinter as tk import sys class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) menubar = tk.Menu(self) fileMenu = tk.Menu(menubar, tearoff=False) menubar.add_cascade(label="File", underline=0, menu=fileMenu) fileMenu.add_command(label="Exit", underline=1, command=quit, accelerator="Ctrl+Q") self.config(menu=menubar) self.bind_all("<Control-q>", self.quit) def quit(self, event): print("quitting...") sys.exit(0) if __name__ == "__main__": app = App() app.mainloop()
也许
from tkinter import * import tkinter.filedialog as filed root = Tk() root.title("My Python Tkinter Application") root.minsize(800,600) def openfile(): fn = filed.askopenfilename(filetypes=[("Text Files","*.txt")], title="Open File") f = open(fn, "r").read() print(f) def init(): menu = Menu(root) filemenu = Menu(menu) filemenu.add_command(label="Open (⌘O)", command=openfile) menu.add_cascade(label="File", menu=filemenu) root.config(menu=menu) def key(): print("Key Pressed: "+repr(event.char)) root.bind("<Key>", key)
也许
相关问题 更多 >
编程相关推荐