Showing Progressbar status based on selection of radio buttons

Tkinter Progressbar

ttk Progressbar to radio buttons



Usually in online surveys user is shown one progress bar reflecting the number of tasks completed.

User has to select six pairs of radio buttons. Each pair of radio button has options Yes and No. User can select any one of the option and user has to complete selecting all six set of buttons.

The progress bar will show the progress based on the completed choices by the user.

There will be a reset button by clicking which the user can reset all the six radio buttons and the progress bar will reset to zero. Each completion of choice will increase the bar by 10 so the maximum value of the progress bar is 60.
Full code is here
import tkinter  as tk 
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")  
def my_upd(): 
    prg1['value']=0
    if(r1_v.get() != 'None'): 
        prg1['value'] += 10
    if(r2_v.get()!='None'): 
        prg1['value'] += 10
    if(r3_v.get()!='None'): 
        prg1['value'] += 10
    if(r4_v.get()!='None'): 
        prg1['value'] += 10
    if(r5_v.get()!='None'): 
        prg1['value'] += 10        
    if(r6_v.get()!='None'): 
        prg1['value'] += 10
    l1.config(text=str(prg1['value'])) #update Label

prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
        length = 320, mode = 'determinate',maximum=60)
prg1.place(relx=.1,rely=.3)    


font1=('times',24,'normal')
l1=tk.Label(my_w,text='value here',font=font1)
l1.place(relx=0.4,rely=0.01)

r1_v = tk.StringVar()
r1_v.set(None) # (default value )
r11 = tk.Radiobutton(my_w,text='Yes', variable=r1_v, value='Yes',command=my_upd)
r11.place(relx=0.1,rely=0.5) 
r12 = tk.Radiobutton(my_w,text='No', variable=r1_v, value='No',command=my_upd)
r12.place(relx=0.2,rely=0.5) 

r2_v = tk.StringVar()
r2_v.set(None) # (default value )
r21 = tk.Radiobutton(my_w,text='Yes', variable=r2_v, value='Yes',command=my_upd)
r21.place(relx=0.4,rely=0.5) 
r22 = tk.Radiobutton(my_w,text='No', variable=r2_v, value='No',command=my_upd)
r22.place(relx=0.5,rely=0.5) 

r3_v = tk.StringVar()
r3_v.set(None) # (default value )
r31 = tk.Radiobutton(my_w,text='Yes', variable=r3_v, value='Yes',command=my_upd)
r31.place(relx=0.7,rely=0.5) 
r32 = tk.Radiobutton(my_w,text='No', variable=r3_v, value='No',command=my_upd)
r32.place(relx=0.8,rely=0.5) 

r4_v = tk.StringVar()
r4_v.set(None) # (default value )
r41 = tk.Radiobutton(my_w,text='Yes', variable=r4_v, value='Yes',command=my_upd)
r41.place(relx=0.1,rely=0.7) 
r42 = tk.Radiobutton(my_w,text='No', variable=r4_v, value='No',command=my_upd)
r42.place(relx=0.2,rely=0.7) 

r5_v = tk.StringVar()
r5_v.set(None) # (default value )
r51 = tk.Radiobutton(my_w,text='Yes', variable=r5_v, value='Yes',command=my_upd)
r51.place(relx=0.4,rely=0.7) 
r52 = tk.Radiobutton(my_w,text='No', variable=r5_v, value='No',command=my_upd)
r52.place(relx=0.5,rely=0.7) 

r6_v = tk.StringVar()
r6_v.set(None) # (default value )
r61 = tk.Radiobutton(my_w,text='Yes', variable=r6_v, value='Yes',command=my_upd)
r61.place(relx=0.7,rely=0.7) 
r62 = tk.Radiobutton(my_w,text='No', variable=r6_v, value='No',command=my_upd)
r62.place(relx=0.8,rely=0.7) 
def my_reset():
    prg1['value']=0
    r1_v.set(None),r2_v.set(None),r3_v.set(None)
    r4_v.set(None),r5_v.set(None),r6_v.set(None)
    l1.config(text='value here ')
b1=tk.Button(my_w,text='Reset',command=lambda:my_reset())
b1.place(relx=0.4,rely=0.8)
my_w.mainloop()  # Keep the window open
Tkinter Progressbar to show status with options and methods to manage and display values

Progressbar

Options : value, mode ,orient ,variable etc.. start() step() and stop() Method example

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer