python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)
python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
下面是tkinter的获取文本框内容_给文本框添加键盘输入事件的操作
运行效果:
在输入的时候,单击回车键,触发:print_contents()

==========================================================
代码部分:
==========================================================
from tkinter import *
__author__ = {'name' : 'Hongten',
'mail' : 'hongtenzone@foxmail.com',
'blog' : 'http://www.cnblogs.com/',
'QQ': '',
'created' : '2013-09-11'}
# This program shows how to make a typein box shadow a program variable.
flag = True
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.entrythingy = Entry(self)
self.entrythingy.pack()
self.button = Button(self, text="Uppercase The Entry",
command=self.upper)
self.button.pack()
# here we have the text in the entry widget tied to a variable.
# changes in the variable are echoed in the widget and vice versa.
# Very handy.
# there are other Variable types. See Tkinter.py for all
# the other variable types that can be shadowed
self.contents = StringVar()
self.contents.set("this is a variable")
self.entrythingy.config(textvariable=self.contents)
# and here we get a callback when the user hits return. we could
# make the key that triggers the callback anything we wanted to.
# other typical options might be <Key-Tab> or <Key> (for anything)
self.entrythingy.bind('<Key-Return>', self.print_contents)
def upper(self):
# notice here, we don't actually refer to the entry box.
# we just operate on the string variable and we
# because it's being looked at by the entry widget, changing
# the variable changes the entry widget display automatically.
# the strange get/set operators are clunky, true...
global flag
flag = not flag
if not flag:
str = self.contents.get().upper()
self.contents.set(str)
else:
str = self.contents.get().lower()
self.contents.set(str)
print('the contents is : ', self.contents.get())
def print_contents(self, event):
print("hi. contents of entry is now ---->", self.contents.get())
root = App()
root.master.title("Foo")
root.mainloop()
参考资料:
http://www.oschina.net/code/explore/Python-3.1.3/Demo/tkinter/matt/entry-with-shared-variable.py
python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件的更多相关文章
- python开发_tkinter_获取单选菜单值
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...
- python开发_tkinter_小球完全弹性碰撞游戏_源码下载
完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改小球的移动速度 ====================== ...
- python开发_tkinter_单选菜单_不可用菜单操作
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_多级子菜单
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_复选菜单
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)
在上一篇blog:python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 中介绍了python中的tkinter的一些东西,你可能对tkinter有一定的了解了.这篇b ...
- python开发_tkinter_小球完全弹性碰撞游戏
python开发_tkinter_小球完全弹性碰撞游戏 完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改 ...
- 【转】python win32api win32gui win32con 简单操作教程(窗口句柄 发送消息 常用方法 键盘输入)
作者:https://blog.csdn.net/qq_16234613/article/details/79155632 附:https://www.programcreek.com/python/ ...
随机推荐
- select()函数用法一
select()函数用法以及FD_ZERO.FD_SET.FD_CLR.FD_ISSET select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用 ...
- redis数据淘汰机制
volatile-lru:从已设置过期时间的数据集(server.db[i].expires)中挑选最近最少使用 的数据淘汰 volatile-ttl:从已设置过期时间的数据集(server.db[i ...
- IIS错误:在唯一密钥属性“fileExtension”设置为“.mp4”时,无法添加类型为“mimeMap”的重复集合项
之前的IIS配置中,.mp4类型的文件默认无法访问,所以个人在IIS7.5的mime类型中增加了.mp4的类型的支持,但问题是需要每台机器中增加这些设置,不利于团队协作,于是,只好将这些修改体现在代码 ...
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
参考学习: 第一篇:http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 第二篇:http://www.jb51.net/a ...
- Python爬取微信好友
前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...
- python网络编程--RabbitMQ
一:RabbitMQ介绍 RabbitMQ是AMPQ(高级消息协议队列)的标准实现.也就是说是一种消息队列. 二:RabbitMQ和线程进程queue区别 线程queue:不能跨进程,只能用于多个线程 ...
- babel转换不了有些es6
bable只转换新语法 不支持新的全局变量如promise async等等,可以使用babel-polyfilll来兼容
- 使用T-SQL导入多个文件数据到SQL Server中
在我们的工作中,经常需要连续输入多个文件的数据到SQL Server的表中,有时需要从相同或者不同的目录中,同时将文件中的数据倒入.在这篇文章中,我们将讨论如何同时把一个目录中的文件的数据倒入到SQL ...
- USACO 6.3 Cryptcowgraphy
CryptcowgraphyBrian Dean The cows of Farmer Brown and Farmer John are planning a coordinated escape ...
- git status中文文件名编码问题解决
在默认设置下,中文文件名在工作区状态输出,中文名不能正确显示,而是显示为八进制的字符编码. 通过将git配置变量 core.quotepath 设置为false,就可以解决中文文件名称在这些Git命令 ...