Zero--- 第一个窗体

python Tk窗体基础学习篇

1---  窗体标签

python Tk窗体基础学习篇

2---  窗体单项选择

python Tk窗体基础学习篇

3----窗体多项选择

 

python Tk窗体基础学习篇

完整代码如下:

from tkinter import *
import tkinter

def run():
     if(CheckVar1.get()==0 and CheckVar2.get()==0 and CheckVar3.get()==0 and CheckVar4.get()==0):
         s = '你还没选择喜欢的表演'
     else:
         s1 = "唱" if CheckVar1.get()==1 else ""
         s2 = "跳" if CheckVar2.get() == 1 else ""
         s3 = "rap" if CheckVar3.get() == 1 else ""
         s4 = "篮球" if CheckVar4.get() == 1 else ""
         s = "你喜欢%s %s %s %s" % (s1,s2,s3,s4)
     lb2.config(text=s)

root = tkinter.Tk()
root.title('复选框')
lb1=Label(root,text='请选择你喜欢的表演')
lb1.pack()

CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar3 = IntVar()
CheckVar4 = IntVar()

ch1 = Checkbutton(root,text='唱',variable = CheckVar1,onvalue=1,offvalue=0)
ch2 = Checkbutton(root,text='跳',variable = CheckVar2,onvalue=1,offvalue=0)
ch3 = Checkbutton(root,text='rap',variable = CheckVar3,onvalue=1,offvalue=0)
ch4 = Checkbutton(root,text='篮球',variable = CheckVar4,onvalue=1,offvalue=0)

ch1.pack()
ch2.pack()
ch3.pack()
ch4.pack()

btn = Button(root,text="确定",command=run)
btn.pack()

lb2 = Label(root,text='')
lb2.pack()
root.mainloop()

相关文章:

  • 2021-09-08
  • 2022-02-20
  • 2021-11-13
  • 2021-10-20
  • 2022-01-09
  • 2022-12-23
  • 2021-05-08
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2021-06-25
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-06-15
相关资源
相似解决方案