欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

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

时间:2021-09-19 07:54:00|栏目: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 实现取多维数组第n维的前几位

栏    目:Python代码

下一篇:pandas.loc 选取指定列进行操作的实例

本文标题:Python弹出输入框并获取输入值的实例

本文地址:http://www.codeinn.net/misctech/176159.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有