강의노트 Scrollbar
강의노트
• 조회수 335
• 댓글 0
• 작성 1년 전
• 수정 9개월 전
scrollbar
스크롤바 위젯과 이를 연결하는 방법에 대하여 알아본다. 스크롤바는 보이는 공간보다 넓은 공간을 사용하는 방법을 제공한다.
스크롤바 위젯은 텍스트나 리스트박스와 다른 독립적인 위젯이다.
스크롤바 위젯을 만드는 방법은 다음과 같다.
scrollbar = ttk.Scrollbar(container, orient='vertical', command=yview)
container는 스크롤바가 포함하는 창 또는 프레임이다.
orient는 스크롤바가 가로로 스크롤할지 세로로 스크롤할지 지정한다.
command는 스크롤바 위젯과 통신할 수 있도록 한다.
예제
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.resizable(False, False)
root.title("Scrollbar Widget Example")
# apply the grid layout
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
# create the text widget
text = tk.Text(root, height=10)
text.grid(row=0, column=0, sticky=tk.EW)
# create a scrollbar widget and set its command to the text widget
scrollbar = ttk.Scrollbar(root, orient='vertical', command=text.yview)
scrollbar.grid(row=0, column=1, sticky=tk.NS)
# communicate back to the scrollbar
text['yscrollcommand'] = scrollbar.set
# add sample text to the text widget to show the screen
for i in range(1,50):
position = f'{i}.0'
text.insert(position,f'Line {i}\n');
root.mainloop()
from tkinter.ttk import *
import tkinter
win=tkinter.Tk()
Progress_Bar=Progressbar(win,orient=HORIZONTAL,length=250,mode='determinate')
def Slide():
import time
for i in range(101):
Progress_Bar['value']=i
win.update_idletasks()
time.sleep(0.01)
Progress_Bar.pack()
Button(win,text='Run',command=Slide).pack(pady=10)
mainloop()
이전 글
다음 글
로그인 하면 댓글을 쓸 수 있습니다.