파이썬 3.6에서 gui_check.py라는 주 코드를 만들고 있습니다.다른 파일에서 파이썬의 버튼으로 함수 읽기하기
코드는 다음과 같습니다
이 코드에서from tkinter import *
from urlread import givenumbers
top = Tk()
top.geometry("400x400")
B = Button(top, text = "Hello", command = givenumbers())
B.place(x = 50,y = 50)
top.mainloop()
, 다른 파일 (라고 urlread.py) 인쇄 번호에서 함수입니다 givenumbers()
라는 함수가 있습니다.
내가 얻고 싶은 결과는 버튼이있는 gui입니다.이 버튼을 클릭하면 함수 givenumber()
이 호출됩니다. 그러나 내가 얻은 결과는 코드를 실행하면 givenumber()
(숫자 인쇄)입니다. 버튼을 클릭하지 않아도 GUI를 열 수 있습니다.
B = Button(top, text = "Hello", command = givenumbers())
그래서 당신이해야합니다 :
[왜 선언 때 실행 버튼 매개 변수 "명령"입니다?]의 사용 가능한 복제 (http://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed- 언제 신고 했습니까? –