-2
class Something:
def buttons(self):
self.button1 = Button(self.main, text = "Add User", command = x)
def Window(self):
self.main = Tk()
self.main.title("Welcome")
self.buttons.button1.grid(row = 0,
column = 0,
columnspan = 2,
rowspan = 2, pady = 5, padx = 5)
self.main.mainloop()
는, I는 클래스 방법 (함수) .buttons()
통해 .Button()
를 호출하여 표시 할 self.buttons
로 시작 코드 행을 원한다.Tkinter : 다른 클래스 메서드에서 Button을 호출하는 방법? 여기
분명히이 코드는 작동하지 않지만이 작업을 수행 할 수있는 더 좋은 방법이 있는지 궁금합니다. 어떤 도움을 주시면 감사하겠습니다.
왜 당신은 그냥 self.button1.grid'호출하지 않습니다 (...)'대신'self.buttons.button1.grid (...)'대신에? – TidB
이 오류가 발생하여 AttributeError : 'Something'객체에 'button1'속성이 없습니다. – tester
버튼을 한 번만 호출하면 버튼이 생성됩니다. 그 후에, 당신은'self.button1'에 의해 그를 액세스 할 수 있습니다. – TidB