我试图使一个类在一次又一次调用该类时显示复选框,而不重写整个代码,而只是通过使用tkinter和python 3.7.2版提供基本变量值。陷入了这个问题。
# easyfunc.py
import tkinter as tk
class checkButton:
"""docstring for checkButton"""
def __init__(self, title, bg, command):
super(checkButton, self).__init__()
self.title = title
self.bg = bg
self.command = command
var = IntVar()
checkbutton = Checkbutton(master, title=title, bg=bg, command=command, variable=var)
checkbutton.pack()
------------------------------------------------------------------------------
# try.py
import easyfunc
def helloworld():
print("helllo")
gui.checkButton("BUTTON", "white", "helloworld")
Traceback (most recent call last):
File "try.py", line 6, in <module>
gui.checkButton("BUTTON", "white", "helloworld")
File "C:\...\easyfunc.py", line 55, in __init__
checkbutton = Checkbutton(master, title=title, bg=bg, command=command, variable=var)
File "C:\...\Python\Python37\lib\tkinter\__init__.py", line 2646, in __init__
Widget.__init__(self, master, 'checkbutton', cnf, kw)
File "C:\...\Python\Python37\lib\tkinter\__init__.py", line 2299, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-title"