-
Notifications
You must be signed in to change notification settings - Fork 0
/
h.py
32 lines (21 loc) · 913 Bytes
/
h.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from tkinter import *
def data():
for i in range(100):
Label(rollFrame,text=i).grid(row=i,column=0)
Label(rollFrame,text="my text"+str(i)).grid(row=i,column=1)
Label(rollFrame,text="..........").grid(row=i,column=2)
# 少了这个就滚动不了
def myfunction(event):
canvas.configure(scrollregion=canvas.bbox("all"),width=200,height=200)
root=Tk()
root.wm_geometry("800x600")
canvas=Canvas(root) # 创建画布
canvas.place(x=0,y=0,height=300,width=500)
myscrollbar=Scrollbar(root,orient="vertical",command=canvas.yview) #创建滚动条
myscrollbar.place(x=500,y=0,height=300)
canvas.configure(yscrollcommand=myscrollbar.set)
rollFrame=Frame(canvas) # 在画布上创建frame
canvas.create_window((0,0),window=rollFrame,anchor='nw') # 要用create_window才能跟随画布滚动
rollFrame.bind("<Configure>",myfunction)
data()
root.mainloop()