우선 순위를 관리하기 위해 간단한 GUI 프로그램을 만들고 있습니다. 다른 기능 내에서 기능에 액세스하는 데 문제가 있습니다. 내 프로그램에서 GuiPart 클래스의 인스턴스를 만든 다음 g.addItem을 호출하려고 시도했지만 그렇게 작동하지 않는 것 같습니다. 오류가 발생합니다.
/usr/bin/python3.5 /home/cali/PycharmProjects/priorities/priorities.py
Traceback (most recent call last):
File "/home/cali/PycharmProjects/priorities/priorities.py", line 70, in > <module>
g.display()
File "/home/cali/PycharmProjects/priorities/priorities.py", line 39, in > display
command = g.addItem)
File "/usr/lib/python3.5/tkinter/__init__.py", line 2077, in grid_configure
+ self._options(cnf, kw))
_tkinter.TclError: bad option "-command": must be -column, -columnspan, -in, > -ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky
내가 한 일은 다음과 같습니다.
# priorities.py
# GUI program to manage priorities
from tkinter import *
class Priority:
def __init__(self, subject, priority):
self.subject = subject
self.priority = priority
def subject(self):
return self.subject
def priority(self):
return self.priority
class GuiPart:
def __init__(self):
self.root = self.createWindow()
def createWindow(self):
root = Tk()
root.resizable(width = False, height = False)
root.title("Priorities")
return root
def createWidgets(self):
listBox = Listbox().grid(row=1)
buttonAdd = Button(text = "Add").grid(row = 2,
column = 0,
sticky = W,
command = g.addItem)
buttonRemove = Button(text="Remove").grid(row = 2,
column = 0,
sticky = W,
command = g.removeItem)
buttonEdit = Button(text="Edit").grid(row = 2,
column = 0,
sticky = E,
command = g.editItem)
textBox = Text().grid(row = 3)
def addItem(self, item):
item = Priority(item.subject, item.priority)
item.subject = g.textBox.get("1.0", 'end-1c')
g.listBox.insert(END, self)
def removeItem(self):
pass
def editItem(self):
pass
class Client:
pass
if __name__ == "__main__":
g = GuiPart()
g.createWidgets()
g.root.mainloop()
코드의 일부를 살펴 보겠습니다.
buttonAdd = Button(text = "Add").grid(row = 2,
column = 0,
sticky = W,
command = g.addItem)
여기서 주된 문제 는 메서드가 아니라 생성자에 command
대한 매개 변수 Button()
라는 .grid()
것입니다. 현재 오류가 발생하는 곳입니다.
두 번째 문제는 할당하는 값이 버튼 자체 가 아니라 (항상 ) buttonAdd
의 결과 라는 것입니다. 나중에 사용하기 위해 버튼에 대한 참조가 실제로 필요한 경우 (종종 필요하지 않음), 이것은 두 개의 문으로 분할되어야합니다..grid()
None
buttonAdd = Button(text = "Add", command = g.addItem)
buttonAdd.grid(row = 2,
column = 0,
sticky = W)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다