text與scrollbar的搭配使用
源自於
https://dotblogs.com.tw/ctosib/2016/11/18/192921
import tkinter as tk
class Mainapplication(tk.Frame):
def __init__(self,master=None):
tk.Frame.__init__(self,master)
self.pack()
self.createwidget()
self.openfile()
def createwidget(self):
self.scrollbar = tk.Scrollbar(self)
self.scrollbar.pack(side=tk.RIGHT,fill=tk.Y)
self.text = tk.Text(self,yscrollcommand=self.scrollbar.set)
self.text.pack(side=tk.LEFT,fill=tk.BOTH)
self.scrollbar.config(command=self.text.yview)
def openfile(self):
with open('1111.txt','r') as f:
temp = f.read()
self.text.insert(tk.END,temp)
if __name__ =='__main__':
root = tk.Tk()
app = Mainapplication(master=root)
root.mainloop()
沒有留言:
張貼留言