2016-05-12 119 views
0

如何製作一個簡單的對話框,要求在python 3中輸入一個整數? 該功能應該類似於input(),它提示用戶,將其保存到變量中,並且在收到輸入之前不會繼續該程序。 它可以使用任何進口,只要它們與python 3兼容。Python 3輸入對話框

+0

1.選擇一個GUI工具包。 2.使用它。 – jonrsharpe

+0

嗯,我不想寫我自己的類,tkinters simpledialog在Python 3中不起作用,並且我知道的所有其他GUI庫都沒有更新到Python 3.如果這很簡單,我不會沒有問過這個問題:) – Theo

回答

0

我已經寫了這段代碼,我希望它能夠做到你想要的,否則請添加評論這個問題,我會嘗試修復它。

from tkinter import * 
def inp(): 
    global inpt 
    number=inpt.get() 
    try: 
     int(number) 
     info.configure(text=number) 
    except ValueError: 
     info.configure(text="Please enter an integer") 
    root.update() 
root=Tk() 
root.geometry("300x100-0+0") 
Label(root,text="Input ", height=1, width=7).grid(row=0) 
inpt=Entry(root, width=35) 
inpt.grid(row=0, column=1) 
info=Label(root,text="", height=1) 
info.grid(row=3, column=1) 
get=Button(root, text="Input", command=inp) 
get.grid(row=2, column=1) 
mainloop()