1 编写一个导航栏

 from tkinter import *

 root = Tk()
root.title("测试")
root.geometry("400x400+400+200")
root.resizable(width = False, height = False) def hello() :
print("hello boy") menubar = Menu(root)
menubar.add_command(label = "hello", command = hello)
menubar.add_command(label = 'quit', command = root.quit) root.config(menu = menubar) root.mainloop()

简例

GUI编程02-LMLPHP

2 编写一个具有下拉菜单的导航栏

 from tkinter import *

 root = Tk()
root.title("测试")
root.geometry("400x400+400+200")
# root.resizable(width = False, height = False) def hello() :
l = Label(root, text = "hello boy")
l.pack() def save() :
l = Label(root, text = "保存文件成功")
l.pack() def cut() :
l = Label(root, text = "剪切成功")
l.pack() def copy() :
l = Label(root, text = "复制成功")
l.pack() def paste() :
l = Label(root, text = "粘贴成功")
l.pack() def about() :
l = Label(root, text = "我是开发者")
l.pack() menubar = Menu(root) # 创建菜单栏对象实例 filemenu = Menu(menubar, tearoff = 0) # 创建下拉菜单栏对象实例
filemenu.add_command(label = "Open", command = hello)
filemenu.add_command(label = "Save", command = save)
filemenu.add_separator() # 添加分割线
filemenu.add_command(label = "Exit", command = root.quit) # 将下拉菜单添加到顶级菜单栏中
menubar.add_cascade(label = "File", menu = filemenu) editmenu = Menu(menubar, tearoff = 0)
editmenu.add_command(label = "Cut", command = cut)
editmenu.add_command(label = "Copy", command = copy)
editmenu.add_separator()
editmenu.add_command(label = "Paste", command = paste)
menubar.add_cascade(label = "Edit", menu = editmenu) helpmenu = Menu(menubar, tearoff = 0)
helpmenu.add_command(label = "About", command = about)
menubar.add_cascade(label = "Help", menu = helpmenu) root.config(menu = menubar) root.mainloop()

简例

GUI编程02-LMLPHP

笔记待更新......

04-28 14:51