在之前的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. Tomcat的JVM设置和连接数设置

    Windows环境下修改“%TOMCAT_HOME%\bin\catalina.bat”文件,在文件开头增加如下设置:set JAVA_OPTS=-Xms256m -Xmx512m Linux环境下修 ...

  2. Linux下配置镜像源

    清华大学地址: https://mirrors.tuna.tsinghua.edu.cn 选择对应ubuntu的版本 在linux下用终端敲 cd /etc/apt/source.list 把里面的内 ...

  3. java 一个函数如何返回多个值

    在开发过程中,经常会有这种情况,就是一个函数需要返回多个值,这是一个问题!! 网上这个问题的解决方法: 1.使用map返回值:这个方法问题是,你并不知道如何返回值的key是什么,只能通过doc或者通过 ...

  4. ls和cd命令详解

    ls命令 命令功能: ​ 列出当前目录下或者指定目录下的所有文件和目录,ls是list的缩写. 命令语法: ls [选项][目录名 ] #注:[ ]中的内容为非必选项 命令选项: | 选项 | 含义 ...

  5. java基础73 dom4j修改xml里面的内容(网页知识)

    1.DOM4J对XML文件进行增删改操作 实现代码 package com.shore.code; import java.io.File; import java.io.FileOutputStre ...

  6. centos7上使用locate命令

    https://blog.csdn.net/yqh19880321/article/details/72426879

  7. 自定义排序及Hadoop序列化

    自定义排序 将两列数据进行排序,第一列按照升序排列,当第一列相同时,第二列升序排列. 在map和reduce阶段进行排序时,比较的是k2.v2是不参与排序比较的.如果要想让v2也进行排序,需要把k2和 ...

  8. 16bit C & ASM 如何混合编译?

    起源: 今天在看以前没看完的一本书<图形程序开发人员指南>,在做里面的例子. 第一章就出问题了,一个例子“L1_2.c, L1_3.asm" ,这是C程序和ASM汇编程序的混合编 ...

  9. Linux下 rz 和 sz 命令的安装与使用

    目录 Linux下 rz 和 sz 命令的安装与使用 rz/sz命令的安装 sz命令-发送文件到本地(下载): rz命令-本地上传文件到服务器(上传): 声明 Linux下 rz 和 sz 命令的安装 ...

  10. thinkphp 5.0 lnmp环境下 无法访问,报错500(public目录)

    两种方法: 1.修改fastcgi的配置文件 /usr/local/nginx/conf/fastcgi.conf fastcgi_param PHP_ADMIN_VALUE "open_b ...