Java321技术网

标题: Python2.7.3 Tkinter Entry(文本框) 说明 [打印本页]

作者: greenss    时间: 2017-6-16 01:29
标题: Python2.7.3 Tkinter Entry(文本框) 说明
本帖最后由 greenss 于 2017-6-16 01:31 编辑

Python学习记录--关于Tkinter Entry(文本框)的选项、方法说明,以及一些示例。
属性(Options)background(bg)#示例from Tkinter import *top = Tk()text = Entry(top, background = 'red')text.pack()mainloop()borderwidth(bd)#示例text = Entry(top, borderwidth = 3)cursorexportselectionfont#示例text = Entry(top, font = ('Helvetica', '14', 'bold')foreground#示例text = Entry(top, foreground = 'red')  #正确text = Entry(top, foreground = '#ff0000')  #正确text = Entry(top, foreground = 'ff0000') #错误,必须加上#号highlightbackground#示例text = Entry(top, highlightbackground = 'red', hightlightthickness = 1)highlightcolor#示例text = Entry(top, highlightcolor = 'red', hightlightthickness = 1)highlightthickness#示例text = Entry(top, highlightcolor = 'red', hightlightthickness = 1)insertbackground#示例text = Entry(top, insertbackground = 'red')insertborderwidth#示例text = Entry(top, insertborderwidth = 3)insertofftime#示例text = Entry(top, insertofftime = 50)insertontime#示例text = Entry(top, insertontime = 50)insertwidth#示例text = Entry(top, insertwidth = 3)justifyrelief#示例text = Entry(top, relief = 'sunken')selectbackground#示例text = Entry(top, selectbackground = 'red')text = Entry(top, selectbackground = '#ff0000')selectborderwidth#示例text = Entry(top, selectborderwidth = 3)selectforeground#示例text = Entry(top, selectforeground = 'red')text = Entry(top, selectforeground = '#ff0000')show#示例text = Entry(top, show = '*')state#示例text = Entry(top, state = 'normal')  #可操作text = Entry(top, state = 'disabled')  #不可操作takefocus#示例待定textvariable#示例default_value = StringVar()default_value.set('This is a default value')text = Entry(top, textvariable = default_value)width#示例text = Entry(top, width = 50)xscrollcommand#示例def callback():        #codetext = Entry(top, command = callback)方法(Methods)insert(index, text)
向文本框中插入值,index:插入位置,text:插入值
#示例text.insert(0, '内容一')  #在文本框开始位置插入"内容一"text.insert(10, '内容二')  #在文本框第10个索引位置插入"内容二"text.insert(END, '内容三')  #在文本框末尾插入"内容三"delete(index), delete(from, to)
删除文本框里直接位置值
#示例text.delete(10)  #删除索引值为10的值text.delete(10, 20)  #删除索引值从10到20之前的值text.insert(0, END)  #删除所有值icursor(index)
将光标移动到指定索引位置,只有当文框获取焦点后成立
#示例text.icursor(10)  #移动光标到索引为10的位置get()
获取文件框的值
#示例text.get()  #返回文本框的值index(index)
返回指定的索引值
#示例text.index(2)  selection_adjust(index), select_adjust(index)
选中指定索引和光标所在位置之前的值
#示例text.selection_adjust(2)  #选中索引为2和光标所有位置之前的所有值selection_clear(), select_clear()
清空文本框
#示例text.selection_clear() selection_from(index), select_from(index)
待定
selection_range(start, end), select_range(start, end)
选中指定索引之前的值,start必须比end小
#示例text.selection_range(2, 10) #选中索引为2和10之前的所有值 selection_to(index), select_to(index)
选中指定索引与光标之间的值(感觉和selection_adjust差不多)
#示例text.selection_to(2) #选中索引为2和所光标所在位置之前的值scan_mark(x)
待定
scan_dragto(x)
待定
xview(x)
待定






欢迎光临 Java321技术网 (https://java321.com/) Powered by Discuz! X3.3