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

yipeiwu_com6年前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实现ping的方法

本文实例讲述了python实现ping的方法。分享给大家供大家参考。具体如下: #!/usr/bin/env python #coding:utf-8 import os, sys,...

Python time库基本使用方法分析

本文实例讲述了Python time库基本使用方法。分享给大家供大家参考,具体如下: 时间获取 time() 获取当前时间戳,为一个浮点数 >>>time....

树莓派使用USB摄像头和motion实现监控

树莓派使用USB摄像头和motion实现监控

本文实例为大家分享了树莓派使用USB摄像头和motion实现监控的具体代码,供大家参考,具体内容如下 一、工具 1、树莓派3B 2、USB摄像头 二、操作步骤 1、安装motion...

Python3.5.3下配置opencv3.2.0的操作方法

Python3.5.3下配置opencv3.2.0的操作方法

1.安装numpy 进入python安装目录的lib下的site-packages文件夹下打开cmd输入pip install numpy下载numpy NumPy系统是Python的...

python实现汉诺塔递归算法经典案例

python实现汉诺塔递归算法经典案例

    学到递归的时候有个汉诺塔的练习,汉诺塔应该是学习计算机递归算法的经典入门案例了,所以本人觉得可以写篇博客来表达一下自己的见解。这markdown编辑...