Hi,
Can anybody help me in creating a progress bar in the UI using Python -TKinter.
Thanks
PSB
4 3055
Here's one that I wrote about a million years ago. Good for example and it works, but I can no longer vouch for the style: - from Tkinter import *
-
from BCDbaseDialog import baseDialog
-
-
class progressDialog(baseDialog):
-
-
def __init__(self, root, label=""):
-
baseDialog.__init__(self, root, title='Progress', label=label)
-
self.canceled = False
-
-
def CreateWidgets(self, top, label):
-
self.frameMain = frameMain = Frame(top, bg=self.bg, borderwidth=2, relief=SUNKEN)
-
Label(frameMain, bg=self.bg, text=label, width=24
-
).grid(row=0, column=0, sticky=EW, columnspan=6, padx=5, pady=10)
-
-
self.meter_x = meter_x = 2
-
self.meter_len = meter_len = 244
-
self.meter = meter = Canvas(frameMain, bg=self.bg, width=meter_len, height=18)
-
meter.grid(row=1, column=0, sticky=EW, columnspan=6, padx=20, pady=5)
-
self.rect = meter.create_rectangle(2, 2, meter_x, 20, fill="black")
-
-
button = Button(frameMain, text='Cancel', command=self.Cancel, takefocus=0)
-
button.grid(row=2, column=5, sticky=EW, columnspan=1, padx=15, pady=10)
-
frameMain.grid(row=0, column=0) # I tried to get rid of flashing here
-
-
def Cancel(self, event=None):
-
self.close()
-
-
def Run(self, progress):
-
delta_p = progress - self.oldprog
-
if delta_p >= self.delta_p:
-
self.oldprog = progress
-
self.meter_x += self.delta_x
-
self.meter.coords(self.rect, 2, 2, self.meter_x, 20)
-
self.top.update()
-
return self.canceled
-
-
def SetMax(self, count):
-
self.count = count
-
if count > self.meter_len:
-
self.delta_x = 1
-
self.delta_p = count//self.meter_len + 1
-
else:
-
self.delta_p = 1
-
self.delta_x = self.meter_len//count
-
self.oldprog = 0
-
-
-
def close(self, event=None):
-
self.canceled = True
-
self.top.destroy()
-
-
##################################
-
-
def AddTestButton(self):
-
button = Button(self.frameMain, text='test', command=self.test, takefocus=0)
-
button.grid(row=2, column=0, sticky=EW, columnspan=1, padx=15, pady=10)
-
-
def test(self):
-
from time import sleep
-
import tkSimpleDialog
-
count = tkSimpleDialog.askinteger('Test', 'How many times?', parent=self.top)
-
self.SetMax(count)
-
st = max(1.0/count * 2, .001)
-
for loop in range(count):
-
canceled = self.Run(loop)
-
if canceled:
-
print 'canceled'
-
break
-
sleep(st)
-
if not canceled:
-
self.close()
-
root.destroy()
-
-
-
if __name__ == '__main__':
-
# test the dialog
-
root = Tk()
-
testDialog = progressDialog(root, 'Cross Referencing')
-
testDialog.AddTestButton()
-
root.mainloop()
-
# root.destroy()
-
I am getting the following error.I need the module BCDbaseDialog to execute the Progress bar.
Thanks & Regards
PSB
>>>
Traceback (most recent call last):
File "C:\Shakil\SAmpleCases\SampleProgress.py", line 2, in -toplevel-
from BCDbaseDialog import baseDialog
ImportError: No module named BCDbaseDialog
I am getting the following error.I need the module BCDbaseDialog to execute the Progress bar.
Thanks & Regards
PSB
>>>
Traceback (most recent call last):
File "C:\Shakil\SAmpleCases\SampleProgress.py", line 2, in -toplevel-
from BCDbaseDialog import baseDialog
ImportError: No module named BCDbaseDialog
Sorry about that. Here's that one: - from Tkinter import *
-
from tkSimpleDialog import _QueryDialog as QueryDialog
-
from tkSimpleDialog import Dialog
-
-
-
class baseDialog:
-
"""Basic dialog window: baseDialog.frameMain is where to put widgets.
-
Pass in option title and label; label will span three columns in the
-
top row. Over-ride CreateWidgets(self, top, label) to add widgets.
-
"""
-
def __init__(self, root, title="", label=""):
-
self.root = root
-
self.top = top = Toplevel(root)
-
top.configure(borderwidth=2)
-
top.geometry("+%d+%d" % (root.winfo_screenwidth()/2,
-
root.winfo_screenheight()/3))
-
self.bg = "white"
-
self.fg = "black"
-
self.CreateWidgets(top, label) # Fit widgets into self
-
top.resizable(height=FALSE, width=FALSE) # then lock the size
-
top.title(title)
-
top.protocol("WM_DELETE_WINDOW", self.close)
-
top.update()
-
# top.tkraise()
-
top.wm_deiconify()
-
-
def CreateWidgets(self, top, label):
-
self.frameMain = frameMain = Frame(top, bg=self.bg, borderwidth=2, relief=SUNKEN)
-
frameMain.grid(row=0, column=0)
-
if label:
-
Label(frameMain, text=label, bg=self.bg, width=24
-
).grid(row=0, column=0, sticky=EW, columnspan=3, padx=5, pady=5)
-
-
-
def close(self, event=None):
-
self.top.destroy()
-
-
-
class QueryHex(QueryDialog):
-
-
errormessage = "Not a hex value"
-
-
def getresult(self):
-
return int(self.entry.get(), 16)
-
-
def validate(self):
-
if QueryDialog.validate(self):
-
self.result = hex(self.result)[2:].zfill(4)
-
return 1
-
return 0
-
-
def askhex(title, prompt, **kw):
-
'''get an integer from the user
-
-
Arguments:
-
-
title -- the dialog title
-
prompt -- the label text
-
**kw -- see SimpleDialog class
-
-
Return value is an integer
-
'''
-
d = QueryHex(title, prompt, **kw)
-
return d.result
-
-
-
class QueryStartEndValue(QueryDialog):
-
## def __init__(self, title, prompt,
-
## initialvalue=None,
-
## minvalue = None, maxvalue = None,
-
## parent = None):
-
-
def body(self, mainFrame):
-
w = Label(mainFrame, text=self.prompt, justify=LEFT)
-
w.grid(row=0, padx=0, sticky=W, columnspan=4)
-
-
Label(mainFrame, text="Start").grid(row=1, column=0, sticky=W, padx=5)
-
Label(mainFrame, text="End").grid(row=1, column=1, sticky=W, padx=5)
-
Label(mainFrame, text="Value").grid(row=1, column=2, sticky=W, padx=5)
-
-
self.start = pyvar = StringVar(self)
-
self.startEntry = entry = Entry(mainFrame, textvariable=pyvar, width=5)
-
entry.grid(row=2, column=0, sticky=EW, padx=5)
-
self.end = pyvar = StringVar(self)
-
self.endEntry = entry = Entry(mainFrame, textvariable=pyvar, width=5)
-
entry.grid(row=2, column=1, sticky=EW, padx=5)
-
self.value = pyvar = StringVar(self)
-
self.valueEntry = entry = Entry(mainFrame, textvariable=pyvar, width=3)
-
entry.grid(row=2, column=2, sticky=W, padx=5)
-
if self.initialvalue:
-
pyvar.set(self.initialvalue)
-
else:
-
pyvar.set('FF')
-
return self.startEntry
-
-
def validate(self):
-
maxvalue = self.maxvalue or 0xffff
-
minvalue = self.minvalue or 0
-
a = self.start.get()
-
b = self.end.get()
-
c = self.value.get()
-
if a or b:
-
try:
-
self.startEntry.select_range(0, END)
-
self.initial_focus = self.startEntry
-
i = int(a, 16)
-
if i < minvalue or i > maxvalue:
-
raise ValueError
-
self.endEntry.select_range(0, END)
-
self.initial_focus = self.endEntry
-
a = hex(i)[2:].zfill(4)
-
if b:
-
j = int(b, 16)
-
if j < minvalue or j < i or j > maxvalue:
-
raise ValueError
-
else:
-
raise ValueError
-
self.valueEntry.select_range(0, END)
-
self.initial_focus = self.valueEntry
-
b = hex(j)[2:].zfill(4)
-
if c:
-
i = int(c, 16)
-
if i > 0xff:
-
raise ValueError
-
c = hex(i)[2:].zfill(2)
-
else:
-
self.value.set('FF')
-
self.valueEntry.select_range(0, END)
-
raise ValueError
-
except ValueError:
-
self.bell()
-
return False
-
self.result = (a, b, c)
-
return True
-
-
-
def askblockvalue(title, prompt='', initialvalue=None,
-
minvalue=0, maxvalue=0x7fff, parent=None):
-
d = QueryStartEndValue(title, prompt, initialvalue, minvalue, maxvalue, parent)
-
return d.result
-
-
if __name__ == '__main__':
-
# test the dialog
-
root = Tk()
-
## def dialog():
-
## baseDialog(root, 'test', 'test')
-
## def dialog():
-
## print askhex("Dump Address", "Enter starting address", minvalue=0, maxvalue=0xffff)
-
def dialog():
-
print repr(askblockvalue('Block Fill', 'Use hex: Start < End < $8000', parent=root))
-
Button(root, text='Dialog', command=dialog).pack()
-
root.mainloop()
-
## if root:
-
## root.destroy()
-
Thanks for the sample code.
How can I identify the % of completion of the task thru my progress bar?.Since I will be doing different tasks by calling methods and I have to push my progress status by so much %.
Thanks
PSB
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
I have try using ant-contrib-03.jar sample from Source Forge, I was
not able to use it. It complains about the following:
foreach, it complains that the trim is not available.
propertycopy, it...
|
by: angelina |
last post by:
Hi,
Can anyone help me write some code that will run a
progress bar before a new form is loaded?
The progressbar does not have to represent the actual
progress of the form load but simply...
|
by: Steven T. Hatton |
last post by:
Some people have suggested the desire for code completion and refined
edit-time error detection are an indication of incompetence on the part of
the programmer who wants such features. ...
|
by: napi |
last post by:
I think you would agree with me that a C compiler that directly
produces Java Byte Code to be run on any JVM is something that is
missing to software programmers so far. With such a tool one could...
|
by: Andrew |
last post by:
Hi Group!
I'm looking for a tutorial in using SQL-DMO, or some sample code that will
allow me to let my users switch the SQL Server database that the front end
app is linking to as a back end.
...
|
by: Daniel Rimmelzwaan |
last post by:
I want to send a biztalk document to an aspx page, and I need to see some
sample code, because I just can't make it work. I have a port with transport
type HTTP, pointing to my aspx page, something...
|
by: bob |
last post by:
Hello,
I want to show progress to the user while some method is running so I
thought I'd use a progress bar.
But I don't see how I can do this without writing GUI code in the
model?
In...
|
by: Chad Z. Hower aka Kudzu |
last post by:
I need to provide a series of demos for an assembly. There are potentialy
several dozen of them. None of them are very complex, however maintaining two
versions of them will be very maintainance...
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |