python|tkinter实现整型/浮点/字符串对话框输入

本博文源于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()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章