zoukankan      html  css  js  c++  java
  • python开发_tkinter_单选按钮

    这篇blog主要是描述python中tkinter的单选按钮操作

    下面是我做的demo

    运行效果:

    ======================================

    代码部分:

    ======================================

     1 from tkinter import *
     2 
     3 # This is a demo program that shows how to
     4 # create radio buttons and how to get other widgets to
     5 # share the information in a radio button.
     6 #
     7 # There are other ways of doing this too, but
     8 # the "variable" option of radiobuttons seems to be the easiest.
     9 #
    10 # note how each button has a value it sets the variable to as it gets hit.
    11 
    12 
    13 class Test(Frame):
    14     def printit(self):
    15         print("hi")
    16 
    17     def createWidgets(self):
    18 
    19         self.flavor = StringVar()
    20         self.flavor.set("chocolate")
    21 
    22         self.radioframe = Frame(self)
    23         self.radioframe.pack()
    24 
    25         # 'text' is the label
    26         # 'variable' is the name of the variable that all these radio buttons share
    27         # 'value' is the value this variable takes on when the radio button is selected
    28         # 'anchor' makes the text appear left justified (default is centered. ick)
    29         self.radioframe.choc = Radiobutton(
    30             self.radioframe, text="Chocolate Flavor",
    31             variable=self.flavor, value="chocolate",
    32             anchor=W)
    33         self.radioframe.choc.pack(fill=X)
    34 
    35         self.radioframe.straw = Radiobutton(
    36             self.radioframe, text="Strawberry Flavor",
    37             variable=self.flavor, value="strawberry",
    38             anchor=W)
    39         self.radioframe.straw.pack(fill=X)
    40 
    41         self.radioframe.lemon = Radiobutton(
    42             self.radioframe, text="Lemon Flavor",
    43             variable=self.flavor, value="lemon",
    44             anchor=W)
    45         self.radioframe.lemon.pack(fill=X)
    46 
    47         # this is a text entry that lets you type in the name of a flavor too.
    48         self.entry = Entry(self, textvariable=self.flavor)
    49         self.entry.pack(fill=X)
    50         self.QUIT = Button(self, text='QUIT', foreground='red',
    51                            command=self.quit)
    52         self.QUIT.pack(side=BOTTOM, fill=BOTH)
    53 
    54 
    55     def __init__(self, master=None):
    56         Frame.__init__(self, master)
    57         Pack.config(self)
    58         self.createWidgets()
    59 
    60 test = Test()
    61 
    62 test.mainloop()

    ========================================================

    More reading,and english is important.

    I'm Hongten

     

    大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。
    Hongten博客排名在100名以内。粉丝过千。
    Hongten出品,必是精品。

    E | hongtenzone@foxmail.com  B | http://www.cnblogs.com/hongten

    ========================================================

  • 相关阅读:
    C语言源代码——计算任何一天是星期几
    计算任意一天是星期几
    wpf利用线程制作初始界面和关闭窗体特效
    实用的 集合工具类 和 String工具类
    从“关于Java堆与栈的思考”一帖看错误信息的传播
    web.xml 配置中classpath: 与classpath*:的区别
    git的安装-环境变量配置
    解决Oracle安装时报错“SID已在使用”办法
    ORACLE日期时间函数
    Java 开发环境配置
  • 原文地址:https://www.cnblogs.com/hongten/p/hongten_python_tkinter_Radiobutton.html
Copyright © 2011-2022 走看看