Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从按钮命令调用的函数与正常调用不同?(蟒蛇)_Python_Tkinter - Fatal编程技术网

Python 从按钮命令调用的函数与正常调用不同?(蟒蛇)

Python 从按钮命令调用的函数与正常调用不同?(蟒蛇),python,tkinter,Python,Tkinter,这里我定义了两个类: from Tkinter import * class Two: def __init__(self): self.main2 = Tk() self.mainFrame2 = Frame(self.main2) self.mainFrame2.pack() self.x= BooleanVar() self.cb = Checkbutton(self.mainFrame2,text=

这里我定义了两个类:

from Tkinter import *

class Two:
    def __init__(self):
        self.main2 = Tk()
        self.mainFrame2 = Frame(self.main2)
        self.mainFrame2.pack()
        self.x= BooleanVar()
        self.cb = Checkbutton(self.mainFrame2,text='tick', variable = self.x)
        self.button2 = Button(self.mainFrame2,text ='button', command = self.Command)

        self.cb.pack()
        self.button2.pack()
        self.main2.mainloop()
    def Command(self):
        print self.x.get()
class One:
    def __init__(self):
        self.main = Tk()
        self.mainFrame = Frame(self.main)
        self.mainFrame.pack()
        self.button = Button(self.mainFrame,text ='Ok', command = lambda: self.callTwo())
        self.button.pack()
        self.main.mainloop()

    def callTwo(self):
        Two()
当我直接打电话的时候

Two()
并勾选复选框,然后单击按钮,它将打印1

但如果我打电话

One()
然后单击确定,勾选复选框,单击按钮,它将打印0


为什么呢?我想调用One()并将其打印1

在tkinter应用程序中不能有两个
Tk
实例。如果要创建多个窗口,请创建
Toplevel
的实例。您只能有一个
Tk
的实例,并且应该只调用
mainloop
一次。

清除并快速响应!正是我需要的!非常感谢你!