|
10鱼币
- import tkinter
- #from Tkinter import *
- def popup(event):
- m2.post(event.x_rott,event.y_root)
- def hello3():
- print('我是剪切命令')
- def hello4():
- print('我是复制命令')
- def hello5():
- print('我是粘贴命令')
- root=Tk()
- root.geometry('400x400+280+280')
- v=StringVar(root)
- m1=Menu(root)
- filemenu=Menu(m1)
- editmenu=Menu(m1)
- viewmenu=Menu(m1)
- for item in ['打开','关闭','退出']:
- filemenu.add_command(label=item,command=hello1)
- for item in ['复制','剪切','粘贴']:
- editmenu.add_command(label=item,command=hello1)
- for item in ['代码','拆分','设计']:
- viewmenu.add_command(label=item,command=hello1)
- m1.add_cascade(label='文件',menu=filemenu)
- m1.add_cascade(label='编辑',menu=editmenu)
- m1.add_cascade(label='视图',menu=viewmenu)
- filemenu.add_separator()
- filemenu.add_checkbutton(label='自动保存',command=hello2,variable=v)
- m2=Menu(root)
- m2.add_command(label='剪切',command=hello3)
- m2.add_command(label='复制',command=hello4)
- m2.add_command(label='粘贴',command=hello5)
- root.bind('<Button-3>',popup)
- root['menu']=m1
- root.mainloop()
复制代码
- # import tkinter 这行注释掉
- from tkinter import * # 这行取消注释,且把 Tkinter 改成 tkinter
- def popup(event):
- m2.post(event.x_rott,event.y_root)
- ################## 你没有写 hello1 和 hello2
- def hello1():
- pass
- def hello2():
- pass
- ##################
- def hello3():
- print('我是剪切命令')
- def hello4():
- print('我是复制命令')
- def hello5():
- print('我是粘贴命令')
- root=Tk()
- root.geometry('400x400+280+280')
- v=StringVar(root)
- m1=Menu(root)
- filemenu=Menu(m1)
- editmenu=Menu(m1)
- viewmenu=Menu(m1)
- for item in ['打开','关闭','退出']:
- filemenu.add_command(label=item,command=hello1)
- for item in ['复制','剪切','粘贴']:
- editmenu.add_command(label=item,command=hello1)
- for item in ['代码','拆分','设计']:
- viewmenu.add_command(label=item,command=hello1)
- m1.add_cascade(label='文件',menu=filemenu)
- m1.add_cascade(label='编辑',menu=editmenu)
- m1.add_cascade(label='视图',menu=viewmenu)
- filemenu.add_separator()
- filemenu.add_checkbutton(label='自动保存',command=hello2,variable=v)
- m2=Menu(root)
- m2.add_command(label='剪切',command=hello3)
- m2.add_command(label='复制',command=hello4)
- m2.add_command(label='粘贴',command=hello5)
- root.bind('<Button-3>',popup)
- root['menu']=m1
- root.mainloop()
复制代码
|
|