Tkinter复选按钮打印输出

时间:2020-10-06 11:17:27

标签: python tkinter tkinter.checkbutton

from tkinter import *
from dialogTable import demos
from quitter import Quitter

class Demo(Frame):
    def __init__(self,parent = None, **options):
        Frame.__init__(self,parent,**options)
        self.pack()
        self.tools()
        Label(self,text = "Check demos").pack()
        self.vars = []
        for key in demos:
            var = IntVar()
            Checkbutton(self,
                        text = key,
                        variable =var,
                        command = demos[key]).pack(side = LEFT)
            self.vars.append(var)

    def report(self):
        for var in self.vars:
            print(var.get(),end = ' ')
        print()
            
    def tools(self):
        frm = Frame(self)
        frm.pack(side = RIGHT)
        Button(frm,text = 'State',command = self.report).pack(fill = X)
        Quitter(frm).pack(fill = X)
        
if __name__ == '__main__':
    Demo().mainloop()     

前面的代码摘自Mark Lutz的“ Programming Python”。有人可以解释为什么报告方法末尾有空白打印功能吗?我尝试了不带打印功能的代码,然后仅当窗口被破坏时才输出输出。

0 个答案:

没有答案