(Python3)- 文本即時更新滾動顯示的方法
(Python3)- 文本即時更新滾動顯示的方法
1. tkinter 文本即時更新滾動顯示
主要加上這句 e4.yview_moveto(1) 就行
e4.insert("end", response.status_code)
e4.insert("end", "++++++++++++++++")
e4.insert("end", "\n\n") # 換行騷操作
e4.yview_moveto(1)
e4.update() # 動態更新text狂
2. Scrollbar 結合 grid 捲軸能拖拽能使用
a、庫引入這兩個
from tkinter import *
import tkinter as tk
b、grid裡添加sticky=S + W + E + N就行
scroll.grid(row=3,column=2, sticky=S + W + E + N)
案例 1
import tkinter as tk
from tkinter import *
from tkinter import scrolledtext
from tkinter import ttk
# root = tk.Tk()
# monty = ttk.LabelFrame(root, text=' Monty Python') # 創建一個容器,其父容器為win
# monty.grid(column=0, row=0, padx=10, pady=10)
# scr = scrolledtext.ScrolledText(monty, width=30, height=5, wrap=tk.WORD)
# scr.grid(column=0, columnspan=3)
# root.mainloop()
root = tk.Tk()
root.grid()
app = ttk.Frame(root)
app.grid()
fram1 = tk.LabelFrame(app, text='1')
txt1 = tk.Text(fram1)
sl1 = Scrollbar(fram1)
sl1['command'] = txt1.yview
# sl1.grid(row=0, column=1,sticky=S + W )
# txt1.grid(row=0, column=0,sticky=S + W )
# fram1.grid(row=0, column=0, sticky=S + W )
sl1.grid(row=0, column=1, sticky=S + W + E + N)
txt1.grid(row=0, column=0, sticky=S + W + E + N)
fram1.grid(row=0, column=0, sticky=S + W + E + N)
mainloop()
案例 2
from tkinter import *
import tkinter as tk
import datetime
import PyQt5.sip
import six
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
nowTime1=datetime.datetime.now().strftime('%Y{}%m{}%d{}').format("年","月","日")
window=tk.Tk()
window.title("資料補充軟體1.0")
window.geometry("790x550+500+200")
# window.columnconfigure(1, weight=1)
l1=tk.Label(window, text="Cookie填入區:", font="微軟雅黑 11", height=2)
l1.grid()
l2=tk.Label(window, text="關鍵字:", font="微軟雅黑 11", height=2)
l2.grid()
l3=tk.Label(window, text="時間段:", font="微軟雅黑 11", height=2)
l3.grid()
e1=tk.Entry(window, width=32)
e1.grid(row=0, column=1)
e2=tk.Entry(window, width=32)
e2.grid(row=1, column=1)
e2.insert(10, '"你好","世界"')
e3=tk.Entry(window, width=32)
e3.grid(row=2, column=1)
e3.insert(10, "2019-03-20-00:2019-03-28-12")
l4=tk.Label(window, text="結果:", font="微軟雅黑 11", height=2)
l4.grid()
# 創建文字方塊text,設置寬度100,high不是高度,是文本顯示的行數設置為3行
e4=tk.Text(window, height=26)
e4.grid(row=3,column=1, sticky=S + W + E + N)
# 創建捲軸
scroll = tk.Scrollbar(orient="vertical", command=e4.yview)
# 將捲軸填充
e4.config(yscrollcommand = scroll.set)
# 將捲軸與文字方塊關聯
# scroll['command']=e4.yview
scroll.grid(row=3,column=2, sticky=S + W + E + N)
mainloop()
免責聲明:
1.本影像檔案皆從網上搜集轉載,不承擔任何技術及版權問題。
2.如有下載連結僅供寬頻測試研究用途,請下載後在24小時內刪除,請勿用於商業。
3.若侵犯了您的合法權益,請來信通知我們,我們會及時刪除,給您帶來的不便,深表歉意。
You have remarked very interesting points! ps nice site. Dionne Doyle Gusti
thx bro.
Glad to be one of several visitants on this awing website :D. Constancia Erl Bautram
If you would like to grow your know-how just keep visiting this weeb page and be updated with the most up-to-date news update posted here. Issi Arman Fritzie Nanon Jarrod Hoxsie
thx u.