zoukankan      html  css  js  c++  java
  • GUI编程02

    1 编写一个导航栏

     1 from tkinter import *
     2 
     3 root = Tk()
     4 root.title("测试")
     5 root.geometry("400x400+400+200")
     6 root.resizable(width = False, height = False)
     7 
     8 def hello() :
     9     print("hello boy")
    10 
    11 menubar = Menu(root)
    12 menubar.add_command(label = "hello", command = hello)
    13 menubar.add_command(label = 'quit', command = root.quit)
    14 
    15 root.config(menu = menubar)
    16 
    17 root.mainloop() 
    简例

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

     1 from tkinter import *
     2 
     3 root = Tk()
     4 root.title("测试")
     5 root.geometry("400x400+400+200")
     6 # root.resizable(width = False, height = False)
     7 
     8 def hello() :
     9     l = Label(root, text = "hello boy")
    10     l.pack()
    11 
    12 def save() :
    13     l = Label(root, text = "保存文件成功")
    14     l.pack()
    15 
    16 def cut() :
    17     l = Label(root, text = "剪切成功")
    18     l.pack()
    19 
    20 def copy() :
    21     l = Label(root, text = "复制成功")
    22     l.pack()
    23 
    24 def paste() :
    25     l = Label(root, text = "粘贴成功")
    26     l.pack()
    27 
    28 def about() :
    29     l = Label(root, text = "我是开发者")
    30     l.pack()
    31 
    32 menubar = Menu(root) # 创建菜单栏对象实例
    33 
    34 filemenu = Menu(menubar, tearoff = 0) # 创建下拉菜单栏对象实例
    35 filemenu.add_command(label = "Open", command = hello)
    36 filemenu.add_command(label = "Save", command = save)
    37 filemenu.add_separator() # 添加分割线
    38 filemenu.add_command(label = "Exit", command = root.quit)
    39 
    40 # 将下拉菜单添加到顶级菜单栏中
    41 menubar.add_cascade(label = "File", menu = filemenu) 
    42 
    43 editmenu = Menu(menubar, tearoff = 0)
    44 editmenu.add_command(label = "Cut", command = cut)
    45 editmenu.add_command(label = "Copy", command = copy)
    46 editmenu.add_separator()
    47 editmenu.add_command(label = "Paste", command = paste)
    48 menubar.add_cascade(label = "Edit", menu = editmenu)
    49 
    50 helpmenu = Menu(menubar, tearoff = 0)
    51 helpmenu.add_command(label = "About", command = about)
    52 menubar.add_cascade(label = "Help", menu = helpmenu)
    53 
    54 root.config(menu = menubar)
    55 
    56 root.mainloop() 
    简例

     

    笔记待更新......

  • 相关阅读:
    PPT能输英文不能输汉字
    常用HTML正则表达式
    Log4j使用总结
    JsonConfig过滤对象属性
    打开”我的电脑“,不显示”共享文档“和”我的文档“,解决办法。(windows XP系统)
    错误org.hibernate.LazyInitializationException
    Tomcat中实现IP访问限制
    windows server 2008中让AD域中的普通用户可以 远程登录 域控服务器。
    ibatis简介及 like查询
    IE访问页面的时候,受限制的解决方案。
  • 原文地址:https://www.cnblogs.com/NeverCtrl-C/p/6652304.html
Copyright © 2011-2022 走看看