python tkinter gui - progress + status updating bar

  Рет қаралды 15,106

Alin Climente

Alin Climente

5 жыл бұрын

Bellow is the code used:
import os
import time
import threading
from tkinter import *
from tkinter import Button, Tk, HORIZONTAL
from tkinter.ttk import Progressbar
from tkinter import messagebox
def percentageCalculator(x, y, case=1):
"""Calculate percentages
Case1: What is x% of y?
Case2: x is what percent of y?
Case3: What is the percentage increase/decrease from x to y?
"""
if case == 1:
#Case1: What is x% of y?
r = x/100*y
return r
elif case == 2:
#Case2: x is what percent of y?
r = x/y*100
return r
elif case == 3:
#Case3: What is the percentage increase/decrease from x to y?
r = (y-x)/x*100
return r
else:
raise Exception("Only case 1,2 and 3 are available!")
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=20, text=field, anchor='w')
ent = Entry(row)
row.pack(side=TOP, fill=X, padx=5, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append((field, ent))
return entries
def processEntry(entries):
infoDict = {}
for entry in entries:
field = entry[0]
text = entry[1].get()
infoDict[field] = text
return infoDict

def runActions(progress, status):
alist = range(10)
log = open("log.txt", "a")
try:
p = 0
for i in alist:
p += 1
Case2: x is what percent of y?
unit = percentageCalculator(p, len(alist), case=2)
#TODO make a decorator!
time.sleep(1) #some func
step = "Working on {}".format(i)
log.write(str('
[OK]'))
progress['value'] = unit
percent['text'] = "{}%".format(int(unit))
status['text'] = "{}".format(step)
root.update()
messagebox.showinfo('Info', "Process completed!")
sys.exit()
except Exception as e:
messagebox.showinfo('Info', "ERROR: {}".format(e))
sys.exit()
log.close()
root = Tk()
root.title("App v0.1")
root.geometry("600x320")
#root.iconbitmap(os.path.join(os.getcwd(), 'favicon.ico'))
fields = 'input1', 'input2', 'input4', 'input5', 'input6'
ents = makeform(root, fields)
runButton = Button(root, text='Start downloading', command=(lambda e=ents: runActions(progress, status)))
percent = Label(root, text="", anchor=S)
progress = Progressbar(root, length=500, mode='determinate')
status = Label(root, text="Click button to start process..", relief=SUNKEN, anchor=W, bd=2)
runButton.pack(pady=15)
percent.pack()
progress.pack()
status.pack(side=BOTTOM, fill=X)
root.mainloop()

Пікірлер: 7
@enricoroselino7557
@enricoroselino7557 Жыл бұрын
so to achieve this with MVC, i guess View need to passed to Model too
@masukinkekhrome365
@masukinkekhrome365 4 жыл бұрын
mohon ijin copy paste
@swiftmaster6826
@swiftmaster6826 Жыл бұрын
you forgot import sys
@voltifer5267
@voltifer5267 4 жыл бұрын
We want to see how to write it and explanation not “...........” and your mouse moving around
@mrarcticaaa1101
@mrarcticaaa1101 4 жыл бұрын
dont be ungrateful
@haunt1175
@haunt1175 2 жыл бұрын
are you an idiot, hes just showing it off, this isn’t a tutorial. if you want that go make it yourself z
Tkinter - Multithreading
38:10
JobinPy
Рет қаралды 5 М.
Python GUI progress bar 📊
10:39
Bro Code
Рет қаралды 58 М.
MEGA BOXES ARE BACK!!!
08:53
Brawl Stars
Рет қаралды 36 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 133 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 123 МЛН
Python GUI tkinter #21 -  Progressbar. Шкала прогресса
8:34
Источник Знаний
Рет қаралды 5 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,5 МЛН
Progress Bars in Python Terminal
11:54
NeuralNine
Рет қаралды 101 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 372 М.
Make Tkinter Look 10x Better in 5 Minutes (CustomTkinter)
4:40
TurbineThree
Рет қаралды 247 М.
Adding A Status Bar - Python Tkinter GUI Tutorial #10
11:04
Codemy.com
Рет қаралды 84 М.
Working with multiple windows in tkinter
13:26
Atlas
Рет қаралды 28 М.
The place layout method in tkinter
20:50
Atlas
Рет қаралды 6 М.