2017-01-13 1 views
0

루프 내에서 창을 여러 번 열어 1,75-225 초 사이의 임의의 값을 매번 닫습니다. 나는이 시도 :Python 3 - tkinter, after() float 사용

from tkinter import * 
from random import * 


root = Tk() 
root.title('Temps inter-essai') 
root.config(bg='black') 
larg_ecr, haut_ecr = root.winfo_screenwidth(), root.winfo_screenheight() 
larg_can, haut_can = larg_ecr/4, haut_ecr/4 

txt = str(larg_ecr) + "x" + str(haut_ecr) 
root.geometry(txt) 

temp=uniform(1.7,2.2) 
root.after(temp,root.destroy) 
root.mainloop() 

내가 실행, 파이썬은 말한다 : "반환 self.tk.call ('시 이후', MS, 이름) _tkinter.TclError : 잘못된 인수"2.992766043938505 "이어야합니다 취소, 유휴, 정보 또는 정수 "

해결 방법이 있습니까? 감사합니다.

답변

2

after()은 초가 아니라 밀리 초 단위로 시간이 걸립니다. 값을 정수로 변환하는 것 외에도 값을 조정해야합니다.

root.after(int(temp * 1000), root.destroy) 
+0

감사합니다. 잘 작동합니다. – Grim

관련 문제