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()