Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI Progress Bar
#1
My program is trying to save an image which takes a little while. I am trying to create a progress bar that will let the user know when the image is saved. The code below is what I have so far. My issue is that PyCharm keeps giving me this error: TypeError: QProgressBar(parent: QWidget = None): argument 1 has unexpected type 'Window'. Any ideas on how to fix this?

from PyQt5.QtWidgets import QWidget, QProgressBar, QPushButton, QApplication
from PyQt5.QtCore import QBasicTimer
import sys

class Window(Frame): #Frame is something inside of tkinter
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.init_window()

        self.progress = QProgressBar(self)
        self.progress.setGeometry(200,80,250,20)

        self.btn = QPushButton("Save", self)
        self.btn.move(200,120)
        self.btn.clicked.connect(self.CreatingFinalImage)
Reply
#2
There's an example here: https://pythonprogramming.net/progress-b...-tutorial/
and it appears to be very similar to what you are doing.
Could you please post the complete error traceback without modification

you should find a bunch of examples on nullege.com but the server seems to be down right now.
Reply
#3
here's a (minimal) PyQt5 version from the example above

import sys
from PyQt5 import QtGui, QtCore, QtWidgets

class Window(QtWidgets.QMainWindow):

    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 500, 100)
        self.setWindowTitle("PyQT tuts!")
        self.setWindowIcon(QtGui.QIcon.fromTheme('text-x-python'))

        self.statusBar().showMessage("Ready", 0)

        self.home()

    def home(self):

        self.progress = QtWidgets.QProgressBar(self)
        self.progress.setGeometry(10, 10, 480, 20)

        self.btn = QtWidgets.QPushButton("Download",self)
        self.btn.move(10,40)
        self.btn.clicked.connect(self.download)

        self.show()

    def download(self):
        self.completed = 0

        while self.completed < 100:
            self.completed += 0.0001
            self.progress.setValue(self.completed)
            self.statusBar().showMessage("downloading ...", 0)
            if self.progress.value() == 100:
                self.statusBar().showMessage("completed", 0)
    
def run():
    app = QtWidgets.QApplication(sys.argv)
    GUI = Window()
    sys.exit(app.exec_())

run()
Reply
#4
Thank you so much, that works beautifully on its own. I have another question. I have a class (shown below*) that I am trying to implement this class in. While the CreatingFinalImage() function is running, I want this progress bar to run. How can I do that?

*Note: I only showed a snippet of my code as it is 1100 lines long

class Window(Frame): #Frame is something inside of tkinter
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.init_window()
    def CreatingFinalImage(self):
        load2 = Image.open(self.picture1) #open the image
        blur = load2.filter(ImageFilter.GaussianBlur(radius=self.blur.get())) #this is a blur function, it makes the spots in the image diminish
        brightness = ImageEnhance.Brightness(blur)
        brightness = brightness.enhance(self.brightness.get()) #this is a brightness function, it brightens the image obviously
Reply
#5
(Aug-22-2018, 05:48 PM)Anysja Wrote: While the CreatingFinalImage() function is running, I want this progress bar to run

Do you know how long it takes to finish?

If no, I would us a wait indicator, something like this
Reply
#6
It takes about 5-10 seconds. It is hard to know when it has saved, which is why I need some sort of indicator it is finished. I will look at that indicator. Thank you for that idea, I didn't think of it.
Reply
#7
I am trying to implement circular progress bar. code is below-
import numpy as np
import math
import matplotlib
import time

def update_bar(steps,lastPos,xc,yc):
percent = lastPos + 2
lastPos = max(1,lastPos)
theta = steps[lastPos:percent]
iX = 0.45*np.cos(theta) + xc
iY = 0.45*np.sin(theta) + yc
oX = 0.35*np.cos(theta) + xc
oY = 0.35*np.sin(theta) + yc
xx = np.matrix(np.zeros([len(theta)*2+1]))
yy = np.matrix(np.zeros([len(theta)*2+1]))
xx[:,0:len(iX)]=iX
xx[:,len(iX):(len(oX)+len(iX))] = oX[::-1]
xx[:,len(theta)*2] = iX[0]
yy[:,0:len(iY)]=iY
yy[:,len(iY):(len(oY)+len(iY))] = oY[::-1]
yy[:,len(theta)*2] = iY[0]
#
# xx = [iX[0], iX[1:len(iX)], oX[::-1], iX[0]]
# yy = [iY[0], iY[1:len(iY)], np.fliplr(oY), iY[0]]
color = [0.91, 0.47, 0.17]
matplotlib.patches( xx, yy)#, color, 'EdgeColor'= color)



def main():
# fig = matplotlib.pyplot.figure()
theta = np.arange(-math.pi,math.pi,0.01,dtype=float)
xc = 0.5
yc = 0.5
x = 0.45*np.cos(theta) + xc
y = 0.45*np.sin(theta) + yc
x1 = 0.35*np.cos(theta) + xc
y1 = 0.35*np.sin(theta) + yc
matplotlib.pyplot.axis('equal')
matplotlib.pyplot.hold(True)
matplotlib.pyplot.plot(x,y,'black',x1,y1,'black')
matplotlib.pyplot.yticks([0,0])
matplotlib.pyplot.xticks([0,0])
# matplotlib.pyplot.hold(False)
# matplotlib.pyplot.show()
steps = np.linspace(-1.5*math.pi, 0.5*math.pi, 100, dtype = float)
lastPos = 0;
for i in range(0,100):
time.sleep(0.001)
# if i>0:
# delete(h)

update_bar(steps,lastPos,xc,yc)
# h = text ( 0.5, 0.5, [str(i) '%'], 'HorizontalAlignment', 'center' );
lastPos = lastPos + 2
if lastPos == 100:
break

main()

please help me, it's not running
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I measure progress and display it in the progress bar in the interface? Matgaret 2 5,926 Dec-11-2019, 03:30 PM
Last Post: Denni
  [Tkinter] Progress Bar While Sending an Email maxtimbo 3 4,092 Oct-09-2019, 09:13 PM
Last Post: woooee
  Progress Bar While Sending an Email maxtimbo 0 2,115 Oct-08-2019, 02:13 PM
Last Post: maxtimbo
  [PyQt] cant import progress bar from another py file swipis 7 8,595 Dec-18-2016, 10:41 AM
Last Post: swipis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020