• 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()
    
  • 相关阅读:
    2个准则,解决人际、团队和客户问题
    系统思维
    如何看透他人行为背后的本质 | 思维模型02:行为分析模型
    提问比回答更有力量
    有了套路,为什么还是解决不了问题
    能够跨界成功的人
    正确的思考
    你的烦恼,全因为不会思考
    努力,到底是不是天赋
    我们是魔术师面前的观众吗
  • 原文地址:https://www.cnblogs.com/amnotgcs/p/12694369.html
Copyright © 2020-2023  润新知