2022年1月8日 星期六

Python Tkinter Progressbar

 Python Tkinter  Progressbar

widget_object = Progressbar(parent, **options)

# importing tkinter module
from tkinter import *
from tkinter.ttk import *
# creating tkinter window
root = Tk()
root.geometry("400x320")
root.title('Progressbar widget in Tkinter')
# Progress bar widget
progress = Progressbar(root, orient = HORIZONTAL,
length = 100, mode = 'determinate')
# Function responsible for the updation
# of the progress bar value
def bar():
import time
progress['value'] = 20
root.update_idletasks()
time.sleep(1)
progress['value'] = 40
root.update_idletasks()
time.sleep(1)
progress['value'] = 50
root.update_idletasks()
time.sleep(1)
progress['value'] = 60
root.update_idletasks()
time.sleep(1)
progress['value'] = 80
root.update_idletasks()
time.sleep(1)
progress['value'] = 100
progress.pack(pady = 10)
# This button will initialize
# the progress bar
Button(root, text = 'Start', command = bar).pack(pady = 10)
Button(root, text = 'Exit', command = root.destroy).pack(pady = 10)
# infinite loop
mainloop()



# importing tkinter module
from tkinter import *
from tkinter.ttk import *
# creating tkinter window
root = Tk()
root.geometry("400x320")
root.title('Progressbar widget in Tkinter')
# Progress bar widget
progress = Progressbar(root, orient = HORIZONTAL,
length = 100, mode = 'indeterminate')
# Function responsible for the updation
# of the progress bar value
def bar():
import time
progress['value'] = 20
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 40
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 50
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 60
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 80
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 100
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 80
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 60
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 50
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 40
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 20
root.update_idletasks()
time.sleep(0.5)
progress['value'] = 0

progress.pack(pady = 10)
# This button will initialize
# the progress bar
Button(root, text = 'Start', command = bar).pack(pady = 10)
Button(root, text = 'Exit', command = root.destroy).pack(pady = 10)

# infinite loop
mainloop()


#========================

from tkinter import *
from tkinter.ttk import *
import time
root = Tk()
root.title('PythonGuides')
root.geometry('400x250+1000+300')
def step():
    for i in range(5):
        root.update_idletasks()
        pb1['value'] += 20
        
        time.sleep(1)
pb1 = Progressbar(root, orient=HORIZONTAL, length=100, mode='indeterminate')
pb1.pack(expand=True)
Button(root, text='Start', command=step).pack(pady = 10)
Button(root, text = 'Exit', command = root.destroy).pack(pady = 10)

root.mainloop()

#==========================

from tkinter import *
from tkinter.ttk import *
import time
root = Tk()
root.title('PythonGuides')
root.geometry('400x250+1000+300')
def step():
    for i in range(5):
        root.update_idletasks()
        pb1['value'] += 20
        time.sleep(0.5)
    
    for i in range(5):
        root.update_idletasks()
        pb1['value'] -= 20       
        time.sleep(0.5)   

pb1 = Progressbar(root, orient=HORIZONTAL, length=100, mode='indeterminate')
pb1.pack(expand=True)
Button(root, text='Start', command=step).pack(pady = 10)
Button(root, text = 'Exit', command = root.destroy).pack(pady = 10)
root.mainloop()

#===============================
from tkinter import *
from tkinter.ttk import Progressbar
import time


root = Tk()
root.title('PythonGuides')
root.geometry('400x350')
root.config(bg='#345')


pb1 = Progressbar(
    root,
    orient = HORIZONTAL,
    length = 50,
    mode = 'determinate'
    )

pb1.place(x=40, y=20)

pb2 = Progressbar(
    root,
    orient = HORIZONTAL,
    length = 100,
    mode = 'indeterminate'
    )

pb2.place(x=40, y=80)

pb3 = Progressbar(
    root,
    orient = HORIZONTAL,
    length = 150,
    mode = 'determinate'
    )

pb3.place(x=40, y=140)

pb1.start()
pb2.start()
pb3.start()

root.mainloop()

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...