zoukankan      html  css  js  c++  java
  • python之tkinter使用-单级菜单

     1 # 菜单功能说明:单级菜单
     2 import tkinter as tk
     3 
     4 root = tk.Tk()
     5 root.title('菜单选择')
     6 root.geometry('200x60')  # 设置窗口大小
     7 
     8 
     9 def file_fn():
    10     print('选择了文件菜单!')
    11     label['text'] = '选择了文件菜单!'
    12 
    13 
    14 def setting():
    15     print('选择了设置菜单!')
    16     label['text'] = '选择了设置菜单!'
    17 
    18 
    19 def directison():
    20     print('选择了说明菜单!')
    21     label['text'] = '选择了说明菜单!'
    22 
    23 
    24 # 创建菜单栏
    25 menubar = tk.Menu(root)
    26 
    27 # 创建菜单项
    28 menubar.add_command(label='文件', command=file_fn)
    29 menubar.add_command(label='设置', command=setting)
    30 menubar.add_command(label='说明', command=directison)
    31 
    32 # 主窗体中加载菜单
    33 root.config(menu=menubar)
    34 
    35 # 标签显示菜单功能
    36 label = tk.Label(root, text='')
    37 label.grid()
    38 
    39 root.mainloop()

    截图:

  • 相关阅读:
    C/C++的区别
    stm32之UCOS-III
    PID控制及整定算法
    PCB设计基础及技巧
    电路的一些基本理论
    stm32与三菱PLC通信
    stm32之外设控制
    stm32之内部功能
    JavaScript数组方法详解
    git新建关联克隆仓库指令
  • 原文地址:https://www.cnblogs.com/gongxr/p/7766771.html
Copyright © 2011-2022 走看看