zoukankan      html  css  js  c++  java
  • Tkinter 控件

    文章更新于:2020-02-19
    待翻译跟进

    In this part of the Tkinter tutorial, we will cover some basic Tkinter widgets. We work with the following widgets: Checkbutton, Label, Scale, and Listbox.

    Widgets are basic building blocks of a GUI application. Over the years, several widgets became a standard in all toolkits on all OS platforms; for example a button, a check box or a scroll bar. Some of them might have different names. For instance, a check box is called a check button in Tkinter. Tkinter has a small set of widgets which cover basic programming needs. More specialised widgets can be created as custom widgets.
    Tkinter Checkbutton

    Checkbutton is a widget that has two states: on and off. The on state is visualized by a check mark. (Some themes may have different visuals.) It is used to denote some boolean property. The Checkbutton widget provides a check box with a text label.

    #!/usr/bin/env python3
    
    """
    ZetCode Tkinter tutorial
    
    This program toggles the title of the
    window with the Checkbutton widget.
    
    Author: Jan Bodnar
    Last modified: April 2019
    Website: www.zetcode.com
    """
    
    from tkinter import Tk, Frame, Checkbutton
    from tkinter import BooleanVar, BOTH
    
    class Example(Frame):
    
        def __init__(self):
            super().__init__()
    
            self.initUI()
    
    
        def initUI(self):
    
            self.master.title("Checkbutton")
    
            self.pack(fill=BOTH, expand=True)
            self.var = BooleanVar()
    
            cb = Checkbutton(self, text="Show title",
                variable=self.var, command=self.onClick)
            cb.select()
            cb.place(x=50, y=50)
    
    
        def onClick(self):
    
            if self.var.get() == True:
                self.master.title("Checkbutton")
            else:
                self.master.title("")
    
    
    def main():
    
        root = Tk()
        root.geometry("250x150+300+300")
        app = Example()
        root.mainloop()
    
    
    if __name__ == '__main__':
        main()
    
  • 相关阅读:
    数据库设计
    vs2013怎么删除代码前的小箭头
    win 7系统自带的截图工具在哪里?如何使用?
    SQL Server不允许保存更改
    多个分组中取每个分组中最新的一条数据
    批量向数据库多张表导入数据的实现
    判断字符串是只是数字
    Mac下查看端口占用情况
    Mac上使用Docker Desktop安装Kubernetes
    关于Lombok框架子类继承时EqualsAndHashCode注解的callSuper取值的思考
  • 原文地址:https://www.cnblogs.com/amnotgcs/p/12694369.html
Copyright © 2011-2022 走看看