카테고리 없음

tkinter progressbar 예제 2탄

gomming 2022. 6. 23. 20:57
import time
import tkinter.ttk as ttk
from tkinter import *

win= Tk()
win.geometry("1100x400+500+200")
win.resizable(False,False)


def clc(): 

    a=int(e1.get())
    for i in range(a):                     
        if a <= 1000:
            time.sleep(0.01)
            var1.set(i+1)
            bar.update()                        
            if var1.get()>=200:
                lab1.config(bg="green")
            else: lab1.config(bg='red')

            if var1.get()>=400:
                lab2.config(bg="green")
            else: lab2.config(bg='red')
                
            if var1.get()>=600:
                lab3.config(bg="green")
            else: lab3.config(bg='red')
                
            if var1.get()>=800:
                lab4.config(bg="green")
            else: lab4.config(bg='red')
                
        else:
            pass
     

e1 = Entry(win,width=10)
e1.pack()

btn1= Button(win, text='시작',width=10,height=3,command=clc)
btn1.pack()

lab1= Label(win,text="서울",bg="red",width=10,height=4,)
lab1.place(x=210,y=200)

lab2= Label(win,text="부산",bg="red",width=10,height=4)
lab2.place(x=410,y=200)

lab3= Label(win,text="대구",bg="red",width=10,height=4)
lab3.place(x=610,y=200)

lab4= Label(win,text="포항",bg="red",width=10,height=4)
lab4.place(x=810,y=200)

lab10= Label(win,text="0",width=10,height=4)
lab10.place(x=10,y=300)

lab100= Label(win,text="100",width=10,height=4)
lab100.place(x=110,y=300)

lab200= Label(win,text="200",width=10,height=4)
lab200.place(x=210,y=300)

lab300= Label(win,text="300",width=10,height=4)
lab300.place(x=310,y=300)

lab400= Label(win,text="400",width=10,height=4)
lab400.place(x=410,y=300)

lab500= Label(win,text="500",width=10,height=4)
lab500.place(x=510,y=300)

lab600= Label(win,text="600",width=10,height=4)
lab600.place(x=610,y=300)

lab700= Label(win,text="700",width=10,height=4)
lab700.place(x=710,y=300)

lab800= Label(win,text="800",width=10,height=4)
lab800.place(x=810,y=300)

lab900= Label(win,text="900",width=10,height=4)
lab900.place(x=910,y=300)

lab1000= Label(win,text="1000",width=10,height=4)
lab1000.place(x=1000,y=300)


var1=DoubleVar()
bar = ttk.Progressbar(win, maximum=1000,length=1000,variable=var1,)
bar.place(x=50,y=300)



win.mainloop()