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() 
    简例

     

    笔记待更新......

  • 相关阅读:
    SQL 视图 局部变量 全局变量 条件语句 事务 触发器
    asp.net中的cookie
    Ajax 学习笔记
    接口与抽象类
    log4net日志组件
    StringBulider简单用法
    Web.Config文件详解
    性能优化之无阻塞加载脚步方法比较
    vue双向数据绑定原理探究(附demo)
    让你的JS更优雅的小技巧
  • 原文地址:https://www.cnblogs.com/NeverCtrl-C/p/6652304.html
Copyright © 2011-2022 走看看