Python - Tkinter输入(Entry): 用于接受用户Entry小窗口部件单行文本字符串.
 
用于接受用户Entry小窗口部件单行文本字符串.
  • 如果你想显示多行文本可以编辑,那么你应该使用文本部件.

  • 如果你想显示一个或多个行文本不能由用户修改,那么你应该使用标签部件.

语法:

这里是一个简单的语法来创建这个widget:

w = Entry( master, option, ... )

参数:

  • master: 这代表了父窗口.

  • options:下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.

Option Description
bg 背后的标签和指标显示正常的背景颜色.
bd 边界周围的指标的大小。默认是2个像素.
command A procedure to be called every time the user changes the state of this checkbutton.
cursor If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that pattern when it is over the checkbutton.
font The font used for the text.
exportselection By default, if you select text within an Entry widget, it is automatically exported to the clipboard. To avoid this exportation, use exportselection=0.
fg The color used to render the text.
highlightcolor The color of the focus highlight when the checkbutton has the focus.
justify If the text contains multiple lines, this option controls how the text is justified: CENTER, LEFT, or RIGHT.
relief With the default value, relief=FLAT, the checkbutton does not stand out from its background. You may set this option to any of the other styles
selectbackground The background color to use displaying selected text.
selectborderwidth The width of the border to use around selected text. The default is one pixel.
selectforeground The foreground (text) color of selected text.
show Normally, the characters that the user types appear in the entry. To make a .password. entry that echoes each character as an asterisk, set show="*".
state The default is state=NORMAL, but you can use state=DISABLED to gray out the control and make it unresponsive. If the cursor is currently over the checkbutton, the state is ACTIVE.
textvariable In order to be able to retrieve the current text from your entry widget, you must set this option to an instance of the StringVar class.
width The default width of a checkbutton is determined by the size of the displayed image or text. You can set this option to a number of characters and the checkbutton will always have room for that many characters.
xscrollcommand 如果你希望用户往往会进入多个widget的屏幕大小的文字,你可以链接进入一个滚动部件.

方法:

以下是这个小工具的常用方法:

Medthod Description
delete ( first, last=None ) 删除字符的部件,在指标之一,但不包括在最后位置的字符开始。如果第二个参数被忽略,只有在单个字符的位置被删除.
get() Returns the entry's current text as a string.
icursor ( index ) Set the insertion cursor just before the character at the given index.
index ( index ) Shift the contents of the entry so that the character at the given index is the leftmost visible character. Has no effect if the text fits entirely within the entry.
insert ( index, s ) Inserts string s before the character at the given index.
select_adjust ( index ) This method is used to make sure that the selection includes the character at the specified index.
select_clear() Clears the selection. If there isn't currently a selection, has no effect.
select_from ( index ) Sets the ANCHOR index position to the character selected by index, and selects that character.
select_present() If there is a selection, returns true, else returns false.
select_range ( start, end ) Sets the selection under program control. Selects the text starting at the start index, up to but not including the character at the end index. The start position must be before the end position.
select_to ( index ) Selects all the text from the ANCHOR position up to but not including the character at the given index.
xview ( index ) This method is useful in linking the Entry widget to a horizontal scrollbar.
xview_scroll ( number, what ) Used to scroll the entry horizontally. The what argument must be either UNITS, to scroll by character widths, or PAGES, to scroll by chunks the size of the entry widget. The number is positive to scroll left to right, negative to scroll right to left.

语法:

自行尝试下面的例子:

from Tkinter import *

top = Tk()
L1 = Label(top, text="User Name")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5) E1.pack(side = RIGHT) top.mainloop()

这将产生以下结果:

 

Tkinter Entry的更多相关文章

  1. Python Tkinter Entry(文本框)

    Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...

  2. Python2.7.3 Tkinter Entry(文本框) 说明

      Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor ...

  3. python tkinter entry

    """小白随笔,大佬勿喷""" '''Entry编辑框 收集数据''' import tkinter as tk import tkinte ...

  4. GUI tkinter (Entry) 输入框篇

    """1.其他函数不常用,这里只说get函数,get函数使用的时候不需要任何参数,它的返回值就是该输入框的内容.""" from tkint ...

  5. tkinter中entry输入控件(四)

    entry控件 import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry("300x200+ ...

  6. tkinter模块常用参数(python3)

    1.使用tkinter.Tk() 生成主窗口(root=tkinter.Tk()):root.title('标题名')    修改框体的名字,也可在创建时使用className参数来命名:root.r ...

  7. Python实现使用tkinter弹出输入框输入数字, 具有确定输入和清除功能

    Python3.6中用tkinter, 弹出可以输入数字的输入框. # Copyright (c) 2017-7-21 ZhengPeng All rights reserved. def pop_u ...

  8. tkinter做一个简单的登陆页面

    做一个简单的登陆页面 import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry("900x3 ...

  9. tkinter属性(总结)

    一.主要控件 1.Button 按钮.类似标签,但提供额外的功能,例如鼠标掠过.按下.释放以及键盘操作事件 2.Canvas 画布.提供绘图功能(直线.椭圆.多边形.矩形) 可以包含图形或位图 3.C ...

随机推荐

  1. loadrunner11 中文破解版安装教程

    loadrunner11的安装:http://pan.baidu.com/share/link?shareid=316642707&uk=1395568298 汉化包(下载之后有可能是ISO格 ...

  2. [Linux] Boot分区满了的处理方法 The volume "boot" has only 0 bytes disk space remaining

    1.查看系统目前正在用的内核 abby@abby:~$ uname -r ..--generic 2.查看/boot保存的所有内核 abby@abby:~$ ls -lah /boot total 3 ...

  3. 05-python中函数的使用

    函数:就是让程序模块化,把具有独立功能的代码块当成一个整体封装成一个函数 首先打印一个佛主看看: print(" _ooOoo_ ") print(" o8888888o ...

  4. 02-C与OC语言的一些小知识

    1.        #import 跟#include.@class有什么区别?#import<> 跟 #import”"又什么区别? 1>  #import和#inclu ...

  5. WEB服务器都在做哪些工作?

    作为WEB开发人员,我们肯定应该要知道WEB服务器都在做哪些工作,这里简单列举一下,有时间然后详细说明. (1)建立连接——接受一个客户端连接. (2)接收请求——从网络中读取一条 HTTP 请求报文 ...

  6. BZOJ3594: [Scoi2014]方伯伯的玉米田【二维树状数组优化DP】

    Description 方伯伯在自己的农田边散步,他突然发现田里的一排玉米非常的不美. 这排玉米一共有N株,它们的高度参差不齐. 方伯伯认为单调不下降序列很美,所以他决定先把一些玉米拔高,再把破坏美感 ...

  7. 禁止别人用QQ号搜索到你,同时告诉你如何破解

    禁止他人用QQ号搜索到我们 举例说明:现在查找自己的QQ号,是可以通过搜索查找到的. 怎么禁止别人搜索到我们呢? 1.打开QQ面板,点击我们的头像. 2.在我们的昵称旁边,有一个小的按钮,点击它可以更 ...

  8. 微信小程序(1)——小程序的特点以及结构

    简单的,用完即走的应用 低频应用 性能要求不高的应用 应用程序入口(app.js   app.json  app.wxss) 一级页面:wxml,wxss,js,json 二级页面:wxml,wxss ...

  9. 接口测试框架——第六篇-读Excel封装方法

    谢谢@小麦苹果的提醒,才发现我借口测试少写了一个文件,今天给大家补上: common->service->excel_case_data.py # coding: utf-8 import ...

  10. [BZOJ5329][SDOI2018]战略游戏

    bzoj luogu Description 省选临近,放飞自我的小Q无心刷题,于是怂恿小C和他一起颓废,玩起了一款战略游戏. 这款战略游戏的地图由n个城市以及m条连接这些城市的双向道路构成,并且从任 ...