在之前的blog中有提到python的tkinter中的菜单操作

python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐

python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)

python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

python开发_tkinter_复选菜单

python开发_tkinter_单选菜单_不可用菜单操作

python开发_tkinter_多级子菜单

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_获取文本框内容_给文本框添加键盘输入事件的更多相关文章

  1. python开发_tkinter_获取单选菜单值

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  2. python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

    我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...

  3. python开发_tkinter_小球完全弹性碰撞游戏_源码下载

    完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改小球的移动速度 ====================== ...

  4. python开发_tkinter_单选菜单_不可用菜单操作

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  5. python开发_tkinter_多级子菜单

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  6. python开发_tkinter_复选菜单

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  7. python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)

    在上一篇blog:python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 中介绍了python中的tkinter的一些东西,你可能对tkinter有一定的了解了.这篇b ...

  8. python开发_tkinter_小球完全弹性碰撞游戏

    python开发_tkinter_小球完全弹性碰撞游戏   完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改 ...

  9. 【转】python win32api win32gui win32con 简单操作教程(窗口句柄 发送消息 常用方法 键盘输入)

    作者:https://blog.csdn.net/qq_16234613/article/details/79155632 附:https://www.programcreek.com/python/ ...

随机推荐

  1. accept系统调用

    /* * For accept, we attempt to create a new socket, set up the link * with the client, wake up the c ...

  2. centos7.2系统没有eth0网卡

    最近一直在学centos7.5系统,偶然看到虚拟机里有7.2系统所以想练习一下(其实7.2和7.5差不多),但是打开虚拟机之后,发现没有eth0网卡 那没有eth0网卡就无法远程连接ssh,既然遇到了 ...

  3. ksh函数

    在不同的shell环境里,shell脚本的写法是不同的 此链接为ksh环境的函数写法: https://blog.csdn.net/shangboerds/article/details/487115 ...

  4. Python 内置装饰器

    内置的装饰器 ​ 内置的装饰器和普通的装饰器原理是一样的,只不过返回的不是函数,而是类对象,所以更难理解一些. @property ​ 在了解这个装饰器前,你需要知道在不使用装饰器怎么写一个属性. d ...

  5. python logging 日志

    logging与print 区别,为什么需要logging? 在写脚本的过程中,为了调试程序,我们往往会写很多print打印输出以便用于验证,验证正确后往往会注释掉,一旦验证的地方比较多,再一一注释比 ...

  6. 树莓派3B安装远程

    步骤1:树莓派3安装 RDP SERVER 及VNC SERVER sudo apt-get install -y tightvncserver sudo vncserver 最后才知道一定要加上VN ...

  7. 21 包含min函数的栈

    定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数. C++: class Solution { private: stack<int> dataStack ; stac ...

  8. Keras中RNN不定长输入的处理--padding and masking

    在使用RNN based model处理序列的应用中,如果使用并行运算batch sample,我们几乎一定会遇到变长序列的问题. 通常解决变长的方法主要是将过长的序列截断,将过短序列用0补齐到一个固 ...

  9. 【LOJ】#2497. 「PA 2017」Banany

    题解 一眼就是线段树维护点分树的dfs序嘛 代码debug一年(手动再见) 码力直线下降,坐等滚粗= = 很明显的我们需要一个点分树,然后求出以每个重心为根的树的dfs序,线段树维护一下每个点的价值- ...

  10. windows svn post-commit 报错解决 error resolving case

    在svn仓库目录下有个hooks目录,下面建一个 post-commit.cmd 文件,有代码提交到仓库,自动checkout到指定目录.   @echo onSET REPOS=%1SET USER ...