当前位置:网站首页>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 Bind mode to get parameters and form validation
- Q_07 词汇表
- 周末看点回顾|我国IPv6网络全面建成;2022昇腾AI开发者创享日·南京站成功举办…
- 行程和用户[阅读理解法]
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面(循环不变量)
- 蓝桥历届真题-既约分数
- 问题系列-如何修改或更新localhost里的值
- Unity3d_API_GPS_LocationService
- 面试攻略系列(二)-- 秒杀系统
- FFmpeg multimedia file processing (ffmpeg prints audio and video Meta information)
猜你喜欢

Come and throw eggs.

Unicom network management protocol block diagram

现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?

GIN中GET POST PUT DELETE请求

TCP三次握手和四次挥手及拥塞控制

群组行动控制--自动队列化实现策略

搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
![行程和用户[阅读理解法]](/img/4b/77bba3c488b5410fdec5c3894c7421.png)
行程和用户[阅读理解法]

FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)

Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
随机推荐
【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
RobotFramework 之 库与关键字
NC40 链表相加(二)
LeetCode 37.解数独
Sandbox中的进程/线程相关-2
自己做了个nodejs+epxress+mysql的小项目,怎么才能让别人通过互联网访问呢?
[FPGA Tutorial Case 48] Image Case 8 - Realization of Converting RGB Image to HSV Image Based on FPGA, Assisted Verification by MATLAB
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
pytest 基础认知
音频基础学习——声音的本质、术语与特性
Record the system calls and C library functions used in this project-2
2.微服务'黑话'集锦及Eureka注册中心相关概念
Q_04_06 把它放在一起:传送
DCT变换与反变换
万物皆可柯里化的 Ramda.js
面试攻略系列(四)-- 你不知道的大厂面试
Q_04_05 使用Qubits
行程和用户[阅读理解法]
NC61 两数之和
RobotFramework 之 资源文件