当前位置:   article > 正文

Python弹出输入框并获取输入值

python弹出输入框并获取输入值

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

  1. from Tkinter import *
  2. import tkMessageBox
  3. def getInput(title, message):
  4. def return_callback(event):
  5. print('quit...')
  6. root.quit()
  7. def close_callback():
  8. tkMessageBox.showinfo('message', 'no click...')
  9. root = Tk(className=title)
  10. root.wm_attributes('-topmost', 1)
  11. screenwidth, screenheight = root.maxsize()
  12. width = 300
  13. height = 100
  14. size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
  15. root.geometry(size)
  16. root.resizable(0, 0)
  17. lable = Label(root, height=2)
  18. lable['text'] = message
  19. lable.pack()
  20. entry = Entry(root)
  21. entry.bind('<Return>', return_callback)
  22. entry.pack()
  23. entry.focus_set()
  24. root.protocol("WM_DELETE_WINDOW", close_callback)
  25. root.mainloop()
  26. str = entry.get()
  27. root.destroy()
  28. return str

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/124881
推荐阅读
相关标签
  

闽ICP备14008679号