Tkinter--Text文本框样例
来源:互联网 发布:观人于微而知其著 编辑:程序博客网 时间:2024/05/17 21:41
#-*- coding:utf-8 -*-"""Text 文本框样例实现功能有:Ctrl+a全选文本, 竖向滚动条,横向滚动条(不自动换行) 自动缩放有谁知道全选文本的方法为会要 return 'break' 吗?http://blog.csdn.net/xxb2008"""import Tkinterclass MainFrame(Tkinter.Frame): def __init__(self, master=None): Tkinter.Frame.__init__(self, master) self.grid(row=0, column=0, sticky="nsew") self.createFrame() def createFrame(self): label_frame_top = Tkinter.LabelFrame(self) #label_frame_top.pack() label_frame_center = Tkinter.LabelFrame(self) label_frame_center.pack(fill="x") lfc_field_1 = Tkinter.LabelFrame(label_frame_center) lfc_field_1.pack(fill="x") self.lfc_field_1_l = Tkinter.Label(lfc_field_1, text="文件路径:", width=10) self.lfc_field_1_l.pack(fill="y", expand=0, side=Tkinter.LEFT) self.lfc_field_1_b = Tkinter.Button(lfc_field_1, text="清除:", width=10, height=1, command=self.clearText) self.lfc_field_1_b.pack(fill="none", expand=0, side=Tkinter.RIGHT, anchor=Tkinter.SE) ##########文本框与滚动条 self.lfc_field_1_t_sv = Tkinter.Scrollbar(lfc_field_1, orient=Tkinter.VERTICAL) #文本框-竖向滚动条 self.lfc_field_1_t_sh = Tkinter.Scrollbar(lfc_field_1, orient=Tkinter.HORIZONTAL) #文本框-横向滚动条 self.lfc_field_1_t = Tkinter.Text(lfc_field_1, height=15, yscrollcommand=self.lfc_field_1_t_sv.set, xscrollcommand=self.lfc_field_1_t_sh.set, wrap='none') #设置滚动条-不换行 #滚动事件 self.lfc_field_1_t_sv.config(command=self.lfc_field_1_t.yview) self.lfc_field_1_t_sh.config(command=self.lfc_field_1_t.xview) #布局 self.lfc_field_1_t_sv.pack(fill="y", expand=0, side=Tkinter.RIGHT, anchor=Tkinter.N) self.lfc_field_1_t_sh.pack(fill="x", expand=0, side=Tkinter.BOTTOM, anchor=Tkinter.N) self.lfc_field_1_t.pack(fill="x", expand=1, side=Tkinter.LEFT) #绑定事件 self.lfc_field_1_t.bind("<Control-Key-a>", self.selectText) self.lfc_field_1_t.bind("<Control-Key-A>", self.selectText) ##########文本框与滚动条end label_frame_bottom = Tkinter.LabelFrame(self) #label_frame_bottom.pack() pass #文本全选 def selectText(self, event): self.lfc_field_1_t.tag_add(Tkinter.SEL, "1.0", Tkinter.END) #self.lfc_field_1_t.mark_set(Tkinter.INSERT, "1.0") #self.lfc_field_1_t.see(Tkinter.INSERT) return 'break' #为什么要return 'break' #文本清空 def clearText(self): self.lfc_field_1_t.delete(0.0, Tkinter.END)def main(): root = Tkinter.Tk() root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) root.geometry('640x360') #设置了主窗口的初始大小960x540 800x450 640x360 main_frame = MainFrame(root) main_frame.mainloop()if __name__ == "__main__": main() pass
http://blog.csdn.net/xxb2008
0 0
- Tkinter--Text文本框样例
- Tkinter--Text文本框样例
- Tkinter学习笔记之Entry&Text输入和文本框
- tkinter使用文本框
- Python---tkinter之Text()
- Tkinter Text 控件
- 小白学tkinter(Text组件)
- 文本框 Text
- python TKinter获取文本框内容
- tkinter之entry和text
- [Tkinter 教程10] Text 控件
- (转)Python2.7.3 Tkinter Entry(文本框) 说明
- Python 窗体(tkinter)输入文本框(entry)
- Text Fields(文本框)
- Tkinter教程之Text(1)篇
- Tkinter教程之Text(2)篇
- Tkinter教程之Text篇(3)
- Python Tkinter教程之Text(1)篇
- Tkinter--HelloWorld
- Tkinter--Button和Scale样例
- 数据、类型常规操作
- JS--刷新当前页面
- Tkinter--GUI布局
- Tkinter--Text文本框样例
- wxPython--基础组件-文本框样例
- wxPython--基础组件-Frame框架样例
- wxPython--基础组件-Menu菜单样例
- wxPython--基础组件-窗体拆分布局
- Python--线程样式
- Python--Socket样例
- 应用安全工作的那些事儿
- http请求信息