Python弹出输入框并获取输入值的实例

yipeiwu_com5年前Python基础

使用自带的Tkinter模块,简单的弹输入框示例,返回输入值

from Tkinter import *
import tkMessageBox
 
 
def getInput(title, message):
  def return_callback(event):
    print('quit...')
    root.quit()
  def close_callback():
    tkMessageBox.showinfo('message', 'no click...')
  root = Tk(className=title)
  root.wm_attributes('-topmost', 1)
  screenwidth, screenheight = root.maxsize()
  width = 300
  height = 100
  size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
  root.geometry(size)
  root.resizable(0, 0)
  lable = Label(root, height=2)
  lable['text'] = message
  lable.pack()
  entry = Entry(root)
  entry.bind('<Return>', return_callback)
  entry.pack()
  entry.focus_set()
  root.protocol("WM_DELETE_WINDOW", close_callback)
  root.mainloop()
  str = entry.get()
  root.destroy()
  return str

以上这篇Python弹出输入框并获取输入值的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

好用的Python编辑器WingIDE的使用经验总结

好用的Python编辑器WingIDE的使用经验总结

WingIDE的使用 好的工具可以让你做事时,事半功倍!这一点在写代码的过程中尤为明显,使用Pyhton写程序有一年多了!各类编辑器IDE也使用了不少,如Pycharm,sublime,...

python tkinter实现界面切换的示例代码

python tkinter实现界面切换的示例代码

跳转实现思路 主程序相当于桌子: import tkinter as tk root = tk.Tk() 而不同的Frame相当于不同的桌布: face1 = tk....

Python中关于Sequence切片的下标问题详解

前言 在python中, 切片是一个经常会使用到的语法, 不管是元组, 列表还是字符串, 一般语法就是: sequence[ilow:ihigh:step] # ihigh,step...

python调用短信猫控件实现发短信功能实例

python调用短信猫控件实现发短信功能实例代码如下所示: #! /usr/bin/env python #coding=gbk import sys import win32com...

对Python函数设计规范详解

Python函数的设计规范 1、Python函数设计时具备耦合性和聚合性 1)、耦合性: (1).尽可能通过参数接受输入,以及通过return产生输出以保证函数的独立性; (2).尽量减...