python - Reverse ttk.Progressbar() -


curious how fill ttk.progressbar() maximum value (any number specified user) , reduce bar step in specified increments. take 100% filled bar (for instance user specifies 100 max value) , reduce 25% every 15 seconds. here i've got:

#import module update frequency , gui. ttk progressbar import threading,ttk tkinter import *  #establishs counter testing purposes counter = 0  #establish window root = tk()  def main():     #user inputs health     health = float(input("enter health:"))      #user inputs how damage each bullet     dps = float(input("enter damage per shot:"))      #user inputs fire rate of weapon     spm = float(input("enter fire rate:"))      #from user inputs establish how many shots takes reduce health or below 0      if ((health / dps).is_integer()) false: #checks if stk value float          stk = int(health / dps) + 1 #since stk value float go next whole number. 33dps doesn't kill in 3 shots.      else: #if stk value integer, establishes stk variable          stk = health / dps      delay_in_seconds = float(60 / spm)      #establishes time kill in seconds, take 1 stk account delay of gunfire     ttki = ((stk - 1) * delay_in_seconds)      # establish progressbar     progre = ttk.progressbar(root, orient='horizontal', maximum=health, mode='determinate')     progre.pack(fill=x)      # test on how test frequency of updating gui once figure out how in heck build     def dps_timer():         global counter         print counter         if counter != (stk-1):             counter += 1             progre.step(float((health/stk)))             root.after(int(ttki*1000/stk), dps_timer)         else:             progre.stop()      # establish gui button     b1 = button(root, text='start', command=dps_timer).pack(fill=x)      root.mainloop()  main() 

so want portion of code

# establish progressbar progre = ttk.progressbar(root, orient='horizontal', maximum=health, mode='determinate') progre.pack(fill=x)  # test on how test frequency of updating gui once figure out how in heck build def dps_timer():     global counter     print counter     if counter != (stk-1):         counter += 1         progre.step(float((health/stk)))         root.after(int(ttki*1000/stk), dps_timer)     else:         progre.stop()  # establish gui button b1 = button(root, text='start', command=dps_timer).pack(fill=x) 

to "hey ttk.progressbar(), depict bar @ 100% / maximum value of health , need reduce @ this step value @ this rate." might provide insight isn't providing me: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-progressbar.html , https://docs.python.org/2/library/ttk.html#index-0

the original code has been revamped gui based, here new code has problem of ttk.progressbar() being initialized chunk missing before start button selected. specify, when start button selected needs held off delay period before first chunk removed.

#import module update frequency , gui. ttk progressbar import ttk tkinter import *  #establish window root = tk() e1 = entry(root) e2 = entry(root) e3 = entry(root) global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter  def captcha_health():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     try:         health = float(e1.get())     except valueerror:         exit()     entry2()  def captcha_dps():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     try:         dps = float(e2.get())     except valueerror:         exit()     entry3()  def captcha_spm():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     try:         spm = float(e3.get())     except valueerror:         exit()     estvar()  def entry2():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     # user inputs how damage each bullet     e2.grid(sticky='we')     db = button(root, text='enter damage/shot', command=captcha_dps).grid()  def entry3():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     # user inputs fire rate of weapon     e3.grid(sticky='we')     sb = button(root, text='enter fire rate', command=captcha_spm).grid()  def estvar():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     # establishs counter testing purposes     counter = 0     # user inputs establish how many shots takes reduce health or below 0     if ((health / dps).is_integer()) false:  # checks if stk value float         stk = int(         health / dps) + 1  # since stk value float go next whole number. 33dps doesn't kill in 3 shots.     else:  # if stk value integer, establishes stk variable         stk = health / dps      delay_in_seconds = float(60 / spm)      # establishes time kill in seconds, take 1 stk account delay of gunfire     ttki = ((stk - 1) * delay_in_seconds)     guiest()  def dps_timer():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     counter += 1     progre.step(-1*dps)     if counter < stk:         root.after(int(ttki*1000/stk), dps_timer)  def guiest():     global health, dps, spm, ttki, stk, delay_in_seconds, progre, counter     # establish gui button     ttklabel = label(root, text='time kill: ' + str(ttki)).grid(sticky=w)     stklabel = label(root, text='shots kill: ' + str(stk)).grid(sticky=w)     hhlabel = label(root, text='health: ' + str(health)).grid(sticky=w)     dpslabel = label(root, text='damage/shot: ' + str(dps)).grid(sticky=w)     spmlabel = label(root, text='fire rate: ' + str(spm)).grid(sticky=w)     delaylabel = label(root, text='delay between shots: ' + str(delay_in_seconds)).grid(sticky=w)     b1 = button(root, text='start', command=dps_timer).grid(sticky='we')     # establish progressbar     progre = ttk.progressbar(root, orient='horizontal', maximum=health, mode='determinate')     progre.grid(sticky='we')     progre.step(health-1)  #user inputs health e1.grid(sticky='we') hb = button(root, text='enter health value', command=captcha_health).grid()  root.mainloop() 

in order set health bar 100%, can use

progre.step(health - 1) 

right above of our dps_timer() function. there, function correct aside step value. want step negative, decreasing value of health bar. also, .stop() useless unless use .start() @ point, can delete chunk of code entirely. once counter equal stk, root.after() won't called anyways, don't need else statement. here's gives us:

def dps_timer():     global counter     print(counter)      if counter < stk:         counter += 1         progre.step(-1*health/stk)         root.after(int(ttki*1000/stk), dps_timer) 

also, progre.step() doesn't remove amount of damage given dps. can fix

progre.step(health - 1)  def dps_timer():     global counter     print(counter)      counter += 1     progre.step(-1*dps)     if counter < stk:         root.after(int(ttki*100/stk), dps_timer) 

(i moved if statement dps_timer isn't called time)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -