本博文源於python基礎,主要針對整型、浮點、字符串對話框輸入進行簡單的測試。包含的內容是基於tkinter下的simpledialog模塊
實驗效果
實驗原理
首先定義用於創建不同類型對話框的消息處理函數,然後將其綁定到相應按鈕上。並上牆到主窗口中
實驗代碼
# -*- coding:utf-8 -*-
import tkinter
import tkinter.simpledialog
def Instr():
r = tkinter.simpledialog.askstring('對話框', 'Input String', initialvalue='tkinter')
print(r)
def InInt():
r = tkinter.simpledialog.askinteger('對話框', 'Input Integer')
print(r)
def InFlo():
r = tkinter.simpledialog.askfloat('對話框', 'Input Float')
print(r)
if __name__ == '__main__':
root = tkinter.Tk()
button1 = tkinter.Button(root, text='Input String', command=Instr)
button1.pack(side='left')
button2 = tkinter.Button(root, text='Input Integer', command=InInt)
button2.pack(side='left')
button3 = tkinter.Button(root, text='Input Float', command=InFlo)
button3.pack(side='left')
root.mainloop()