当前位置:网站首页>tkiner组件之滚动文本框(scrolledtext )相关操作
tkiner组件之滚动文本框(scrolledtext )相关操作
2022-08-09 13:07:00 【论一个测试的养成】
1.创建一个滚动文本框
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('text')
root.geometry('100x100')
scr = scrolledtext.ScrolledText(root,width=10,height=5)
scr.pack()
root.mainloop()
如图
2.读取text文件内容显示到滚动文本框
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('text')
root.geometry('300x100')
scr = scrolledtext.ScrolledText(root,width=50,height=5)
scr.pack()
with open('test') as f:
for line in f:
scr.insert('end',line)#末尾插入
#scr.insert('insert',line)#光标插入
root.mainloop()
如图:
3.文本内容的删除
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('text')
root.geometry('300x100')
scr = scrolledtext.ScrolledText(root,width=50,height=5)
scr.pack()
for i in range(10):
scr.insert('end', i)
scr.insert('end', '\n')
scr.delete(1.0) #删除第一个元素
scr.delete(1.0,'end') #删除所有元素
root.mainloop()
4.文本内容的获取
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('text')
root.geometry('300x100')
scr = scrolledtext.ScrolledText(root,width=50,height=5)
scr.pack()
for i in range(10):
scr.insert('end', i)
scr.insert('end', '\n') #
print(scr.get(1.0,'end')) #获取文本中所有内容
print(scr.get(1.0)) #获取文本中第一行的内容
root.mainloop()
5.打印选中的文本内容
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('text')
root.geometry('300x100')
scr = scrolledtext.ScrolledText(root,width=50,height=5)
scr.pack()
for i in range(10):
scr.insert('end', i)
scr.insert('end', '\n') #
def showselection():
try:
s = scr.selection_get()
except Exception as e:
print('....')
else:
print(s)
tk.Button(root,text='sava',command=showselection).pack()
root.mainloop()
如图:
边栏推荐
- GIN文件上传与返回
- Realization of RTSP Protocol
- 搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
- 程序员的七夕怎么过?不会是写代码吧
- Q_07 词汇表
- Deep Learning Based on R Language - Simple Regression Case
- The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)
- 关于做2D游戏时,Canvas边界显示在Game窗口的问题
- Unity3d_API_Gyroscope 陀螺仪的接口
- FFmpeg av_interleaved_write_frame错误
猜你喜欢
pytest 之 fixture的定义及作用域
eslint语法规则报错
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
IDEA Gradle 常遇问题(二)(持续更新)
pytest 之 allure报告
The FPGA - work summary recently
【瑞吉外卖】day05:增、删、改、查分类以及公共字段自动填充
01_iTween_第一天--小球抛物线
jenkins api create custom pipeline
pytest 之 fixture的调用
随机推荐
[FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
RobotFramework 之 Evaluate
利用信号灯和共享内存实现进程间同步通信
19、学习MySQL 索引
快来扔鸡蛋。
程序员的七夕怎么过?不会是写代码吧
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
GIN文件上传与返回
剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
render解析
NC192 二叉树的后序遍历
群组行动控制--自动队列化实现策略
WSA toolkit installed app store tip doesn't work how to solve?
CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
【瑞吉外卖】day05:增、删、改、查分类以及公共字段自动填充
offset、client、scroll、window.pageYOffset比较
FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)
Unity3d_API_Gyroscope 陀螺仪的接口
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
力扣解法汇总1413-逐步求和得到正数的最小值