I have a 2 vertical lines on a canvas with a gap in the middle (generated randomly every time). This line starts on the right side of the canvas. When I click the "l" key it runs a function that moves the line left by 5, and you can keep clicking "l" until it reaches the left side. I want to know how to set it up so I only have to press the "l" key once and the line will slowly move across the screen until it reaches the left side. Any help would be appreciated
import random
import time
from tkinter import *
window = Tk()
window.geometry("300x300")
window.title("GUI")
window.resizable(FALSE, FALSE)
label1 = Label(window, text="My First GUI", font=("arial", 16, "bold"))
label1.pack()
canvas = Canvas()
canvas.config(bg="gray")
canvas.place(width=300, height=150, x=0, y=150)
def key_pressed(event):
if event.char == "l":
move_line()
def create_gap():
gap_ycoords = []
# random number between 10 and 95 in increments of 5
first_line_end = random.randrange(10, 96, 5)
gap_ycoords.append(first_line_end)
second_line_start = first_line_end + 50
gap_ycoords.append(second_line_start)
return gap_ycoords
def draw_line_obstacle(canvas_ref):
y_coord = create_gap()
top_line = canvas_ref.create_line(295, 5, 295, y_coord[0], tags="top_line")
bottom_line = canvas_ref.create_line(295, y_coord[1], 295, 145, tags="bottom_line")
draw_line_obstacle(canvas)
def move_line():
if canvas.coords("top_line")[0] > 5:
tcoords = canvas.coords("top_line")
bcoords = canvas.coords("bottom_line")
canvas.coords("top_line", tcoords[0] - 5, tcoords[1], tcoords[2] - 5, tcoords[3])
canvas.coords("bottom_line", bcoords[0] - 5, bcoords[1], bcoords[2] - 5, bcoords[3])
window.bind("<Key>", key_pressed)
window.mainloop()
You're so close! Only one more line needed in your move_line function:
def move_line():
if canvas.coords("top_line")[0] > 5:
... # other code
canvas.after(100, move_line) # delay in ms, lower=faster movement
You need to use .after(). This basically calls a function every, say, 20 milliseconds.
Calling this function repeatedly will make it so that when you press the "l" key once, the line will move to the other end of the screen.
Code:
import random
import time
from tkinter import *
window = Tk()
window.geometry("300x300")
window.title("GUI")
window.resizable(FALSE, FALSE)
label1 = Label(window, text="My First GUI", font=("arial", 16, "bold"))
label1.pack()
canvas = Canvas()
canvas.config(bg="gray")
canvas.place(width=300, height=150, x=0, y=150)
def key_pressed(event = None):
move_line()
window.after(20, key_pressed)
def create_gap():
gap_ycoords = []
# random number between 10 and 95 in increments of 5
first_line_end = random.randrange(10, 96, 5)
gap_ycoords.append(first_line_end)
second_line_start = first_line_end + 50
gap_ycoords.append(second_line_start)
return gap_ycoords
def draw_line_obstacle(canvas_ref):
y_coord = create_gap()
top_line = canvas_ref.create_line(295, 5, 295, y_coord[0], tags="top_line")
bottom_line = canvas_ref.create_line(295, y_coord[1], 295, 145, tags="bottom_line")
draw_line_obstacle(canvas)
def move_line():
if canvas.coords("top_line")[0] > 5:
tcoords = canvas.coords("top_line")
bcoords = canvas.coords("bottom_line")
canvas.coords("top_line", tcoords[0] - 5, tcoords[1], tcoords[2] - 5, tcoords[3])
canvas.coords("bottom_line", bcoords[0] - 5, bcoords[1], bcoords[2] - 5, bcoords[3])
window.bind("<l>", key_pressed)
window.mainloop()
On this line: window.after(20, key_pressed), you can change the number 20 to something higher to move slower, and something lower to move faster.
Hope this helps!
Related
Error inside of the terminal.
/Users/aidan/Documents/GitHub/Perceptual/Threading.py:81: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
plt.show()
2022-11-06 14:28:07.960 Python[25376:1206036] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
Code of the python project.
import time
import tkinter as tk
#import tkinter as tkk
from tkinter.ttk import *
from PIL import Image, ImageTk
import random
import threading
#imports for BackEnd
import pyautogui as mouse
import matplotlib.pyplot as plt
#Created Global Array
x = []
y = []
root = tk.Tk()
root.title("Perceptual Threading")
root.geometry("900x600")
#Sperates the canvase into diffrent coloms
root.columnconfigure(6, weight = 0)
root.rowconfigure(10, weight = 0)
def BackEndDebug():
DebugInt = 0
while(DebugInt != -1):
DebugNumber.config(text=f'Random Number: {DebugInt}')
DebugInt += 1
time.sleep(0.0000000001)
#Load Logo
def LoadLogo():
logo = Image.open("PerceptualLogoTransparent.png")
logo = logo.resize((125, 125))
logo = ImageTk.PhotoImage(logo)
logo_label = tk.Label(image = logo)
logo_label.image = logo
logo_label.grid(column=0, row=0, sticky=tk.W, padx=5, pady=5)
def LoadDashboard():
Dashboard = Image.open("Mercades Dashboard .jpeg")
Dashboard = Dashboard.resize((775,300))
Dashboard = ImageTk.PhotoImage(Dashboard)
Dashboard_label = tk.Label(image = Dashboard)
Dashboard_label.image = Dashboard
Dashboard_label.grid(column = 2, row = 6, columnspan=3, rowspan=2)
def MouseGraph():
control = True
count = 0
t = 1
inc = .1
check1, check2, check3 = 0, 1, 2
mouse.moveTo(960, 540)
while control:
thing = mouse.position()
y.append(thing[0] - 960)
x.append(inc * t)
if thing[1] > 540 or thing[1] < 540:
mouse.moveTo(thing[0], 540)
count += 1
t += 1
if count > 2:
if (y[check2] < y[check1] and y[check2] < y[check3]) or (y[check2] == y[check1] and y[check2] < y[check3]):
print(f'{y[check2]} is the relative minimum.')
if (y[check2] > y[check1] and y[check2] > y[check3]) or (y[check2] == y[check1] and y[check2] > y[check3]):
print(f'{y[check2]} is the relative maximum.')
check1 += 1
check2 += 1
check3 += 1
if count > 100:
control = False
# return(x, y)
plt.plot(x, y)
plt.xlabel('time')
plt.ylabel('distance turned')
plt.show()
time.sleep(inc)
DebugNumber = Label(root, text="Debug Number!")
DebugNumber.grid(column= 6, row= 0, sticky=tk.E)
StartBackendDebug = Button(root, text="Start the BackendDebug", command = threading.Thread(target=BackEndDebug).start)
StartBackendDebug.grid(column= 5, row= 0, sticky=tk.E)
StartGraph = Label(root, text="Start Graph!")
StartGraph.grid(column= 6, row= 1, sticky=tk.E)
StartGraphButton = Button(root, text="Begin", command = threading.Thread(target=MouseGraph).start)
StartGraphButton.grid(column= 5, row= 1, sticky=tk.E)
LoadLogo()
LoadDashboard()
root.mainloop()
I have tried returning the arrays after making them global variables but I do not know how to then have a call after the thread is over. This is my first project using threading and am unsure if I need to add classes or what. Is there a way to call the method of a class from another class or run the code in the main thread without Tkinter having an issue. I have also tried looking into other graphing methods but this seems to be the only real way.
I have written a program and would like to export it to an .exe file. I used cx-freeze, and, although it normally works, it hasn't worked with this code. The converted .exe file won't open.
from ctypes import windll
import tkinter as tk
from tkinter import ttk
from pynput.mouse import Controller
from pynput.mouse import Button, Controller
import time
import webbrowser
from tkinter import messagebox
import keyboard
#from tkinter import *
def start():
window2.destroy()
hdc = windll.user32.GetDC(0)
mouse = Controller()
webbrowser.open('https://games.htmlgames.com/WhackEmAll/')
time.sleep(5)
def wait_until(x, y, operation, colour, wait):
hdc = windll.user32.GetDC(0)
if operation == '!':
while windll.gdi32.GetPixel(hdc, x, y) != colour:
time.sleep(wait)
if operation == '=':
while windll.gdi32.GetPixel(hdc, x, y) == colour:
time.sleep(wait)
def click_on(x, y, wait):
mouse.position = (x, y)
mouse.click(Button.left, 1)
time.sleep(wait)
wait_until(802, 444, '!', 16777215, 1)
click_on(802, 444, 1)
click_on(684, 632, 1)
click_on(847, 539, 0)
start = time.time()
end = start + 60
x_pos = [455, 725, 885, 455, 670, 885, 455, 670, 885,]
y_pos = [315, 315, 315, 495, 495, 495, 675, 675, 675]
colour_mole = [15263718, 10277608]
time.sleep(1)
window = tk.Tk()
def exit(event):
window.destroy()
stop = 2
window.bind("<Escape>", exit)
window.wm_attributes("-topmost", 1)
window.title("AI")
label0 = tk.Label(window, text="Welcome to my Whac-A-Mole AI!", font=("Helvetica 10 bold"), fg = "blue")
label1 = ttk.Label(window, text="Hold ESC for 1 sec to exit the AI", font=("Helvetica 10 bold"))
label0.grid(row=0, column=0)
label1.grid(row=1, column=0)
while time.time() <= end and not keyboard.is_pressed('Esc'):
window.update_idletasks()
window.update()
for x in x_pos:
for y in y_pos:
if windll.gdi32.GetPixel(hdc, x, y) in colour_mole:
mouse.position = (x, y)
mouse.click(Button.left, 1)
window.destroy()
window.mainloop()
window2 = tk.Tk()
window2.title("AI")
window2.resizable(0,0)
t2_label0 = tk.Label(window2, text="Welcome to my Whac-A-Mole AI!", font=("Helvetica 10 bold"), fg = "blue")
t2_label1 = ttk.Label(window2, text=" Press Start to begin the AI")
t2_label2 = ttk.Label(window2, text=" You will only be able to stop the program once the game has begun")
t2_label3 = tk.Label(window2, text="WARNING: THIS PROGRAM WILL CONTROL YOUR MOUSE", fg = "red")
t2_label0.grid(row=0, column=0)
t2_button = ttk.Button(window2, text = "Start", command = start)
t2_label3.grid(row = 4, column=0)
t2_button.grid(row = 3, column=0)
t2_label1.grid(row=1, column=0)
t2_label2.grid(row = 2, column=0)
window2.attributes("-topmost", True)
window2.mainloop
I do not know what has happened. I even tried with exemaker and pyinstaller but these didn't work either. Could someone please tell me what happened and how to fix it?
you should try using Auto Py To Exe, i use that tool for all my tkinter projects, and it has worked perfectly!
My title may be kind of confusing, but I essentially want to draw a different set of shapes every four seconds then start over. For example, second one I want to draw triangles, second two I want to draw lines, second three I want to draws rectangles, and second four I want to draw ovals. The for second five I want this process to repeat. My Idea was to use the remainder which works up to second seven. Also is this possible to do without importing any additional modules. Any help would be great and if something was not clear please ask.
Thanks,
Scott
Here is my current code to run if you want:
from tkinter import *
from random import *
#creates a class
class mainWindow():
def __init__(self,theWindow,winName):
#Sets values for variable
self.running = 0
#makes theWindow and instnace var
self.theWindow = theWindow
#creates the main frames
self.mainFrame = Frame(theWindow,width=600,height=200,bg="light gray")
self.secondframe = Frame(theWindow,width=600, height =287, bg = "green")
self.mainFrame.grid()
self.secondframe.grid()
# gives the window a title
theWindow.title(winName)
# do not resize window based on widgets
self.mainFrame.grid_propagate(False)
# window location
theWindow.geometry('+500+300')
#Makes it so the window wont resize
self.theWindow.resizable(0,0)
#
self.theWindow.wm_attributes("-topmost",1)
`enter code here`#Creates the three frames that will be used
#Inerts a blank label to help with formating
self.blank1 = Label(self.mainFrame, bg= "light gray", height =3, width=19)
self.blank1.grid(row=0, column=0, rowspan =1)
#Creates and places the start button
self.startbutton = Label(self.mainFrame,text = "Start", bg= "green", height =1, width=10,relief=RAISED)
self.startbutton.bind("<Button-1>", self.startTimer)
self.startbutton.grid(row=0, column=2, rowspan =1, sticky = E)
#Creates and places the stop button
self.stopbutton = Label(self.mainFrame,text = "Stop", bg= "red", height =1, width=10,relief=RAISED)
self.stopbutton.bind("<Button-1>", self.endTimer)
self.stopbutton.grid(row=0, column=3, rowspan =1, sticky =W)
#Creates and places the timer
self.timerLabel = Label(self.mainFrame,text = "Time: 0", bg= "white", height =2, width=14,relief=SUNKEN)
self.timerLabel.bind("<Button-1>",)
self.timerLabel.grid(row=3, column=2, columnspan =2, pady =25)
#draws the canvas
self.drawCanvas = Canvas(self.secondframe,width=598,height=285, bg= "light green")
self.drawCanvas.grid()
#Function for strting the timer
def startTimer(self,event):
if self.running == 0:
self.running = 1
self.countElapse(0)
#function for ening the timer
def endTimer(self,event):
if self.running == 1:
self.running = 0
self.timecount = 0
self.drawCanvas.delete(ALL)
self.timerLabel.configure(text = "Time: %d" %0)
#function for showing the time
def countElapse(self,localTime = NONE):
#self.timerLabel.configure()
if self.running:
if localTime is not NONE:
self.timecount = localTime
self.timerLabel.configure(text ="Time: "+str(self.timecount+1))
self.timecount = self.timecount+1
self.drawshapes(self.timecount)
self.mainFrame.after(1000,self.countElapse)
#function for drawing the shpaes
def drawshapes(self,timecount):
self.drawCanvas.delete(ALL)
color = ["red","white","purple","green","lime green", "cyan", "black","light blue","blue","pink","brown","gray"]
numshapes = 100
counter = 0
print(self.timecount)
var = self.timecount
#draws ovals
if var % 4 ==0:
while counter != numshapes:
counter += 1
x = randint(10,600)
y = randint(10,600)
x1 = randint(10,600)
y1 = randint(10,600)
#draws the shape
self.drawCanvas.create_oval(x,y,x1,y1,fill=choice(color))
#draws rectangles
elif var % 3 ==0:
while counter != numshapes:
counter += 1
x = randint(10,600)
y = randint(10,600)
x1 = randint(10,600)
y1 = randint(10,600)
self.drawCanvas.create_rectangle(x,y,x1,y1,fill= choice(color))
#draws Lines
elif var % 2 ==0:
while counter != numshapes:
counter += 1
x = randint(10,600)
y = randint(10,600)
x1 = randint(10,600)
y1 = randint(10,600)
self.drawCanvas.create_line(x,y,x1,y1,fill= choice(color))
#draws triangles
elif var % 1 ==0:
while counter != numshapes:
counter += 1
x = randint(10,600)
y = randint(10,600)
x1 = randint(10,600)
y1 = randint(10,600)
x2 = randint(10,600)
y2 = randint(10,600)
self.drawCanvas.create_polygon(x,y,x1,y1,x2,y2,fill= choice(color))
def main():
# create a tkinter object
mainWin = Tk()
# create a mainWindow object
theMainWin = mainWindow(mainWin,"Scott Rodgers")
# keep the window displaying
mainWin.mainloop()
#calls main
main()
What you are looking for is how to use the .after method.
Here is how it works.
Lbl = Label()
Lbl.pack()
Lbl.after([Amount of milliseconds], lamba: [Function])
For more advanced notation,
after(delay_ms, callback=None, *args)
What this does is that it registers an alarm callback that is called after a given time
I'm writing a scientific calculator with 2nd button. What is the function for second button so for example it changes sin to sin^-1, plus changing the sin button command; and if you click the 2nd button again, it changes sin^-1 back to sin
I would split my calculator up into section using different frames (one to show the calculations , one with buttons which won't have 2 functions and lastly the buttons which have 2 functions).
The reason I would split it up is because I would use destroying objects and making the new ones this splitting up means you can destroy the wanted frame rather than specific buttons (would require less code). Also for this I would have 3 create GUI defs. one would be the buttons with one function and the bit showing the calculations. one be the buttons which have 2 functions (their first function) and lastly the buttons which have 2 functions (their second functions). To decide between which GUI gen def to use have an if statement with global variable which gets changed each time 2nd function button called and that decides which def to use.
If it was just commands you wanted changing instead of both labels and commands I would have a variable which is etheir 1 or 2(change when 2nd button clicked) then in your definitions (ones which your buttons call) have an if statement to decide between to do normal action (e.g cos) or 2nd action (e.g cos-1).
Here is code below that uses what i have described in the first paragraph:
from tkinter import *
class Calc(Frame):
def __init__(self, master):
self.modefunction = 1
""" Initialize the frame. """
super(Calc,self).__init__(master)
self.grid()
self.calculations_frm = Frame(self, width=100, height=30)#bg = "red"
self.calculations_frm.grid(row = 0, column = 0, columnspan=2)
self.buttons_frm = Frame(self, width= 50, height=30,)#bg = "green")
self.buttons_frm.grid(row = 1, column = 1)
self.buttons_2_functions_1_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_1_frm.grid(row = 1, column = 0)
self.create_GUI()
def create_show_calculations(self):
self.calculation_lbl = Label(self.calculations_frm, text = "will show caluclations here").pack()
def create_buttons(self):
#mc stands for mode change
self.mode_change_btn = Button(self.buttons_frm, text = "mc", command = self.mode_change, height = 1, width = 5)
self.mode_change_btn.grid(row = 0,column = 0)
self.plus_btn = Button(self.buttons_frm, text = "plus", height = 1, width = 5)
self.plus_btn.grid(row = 1,column = 0)
def create_GUI(self):
self.create_show_calculations()
self.create_buttons()
self.create_1_function_gui()
def create_1_function_gui(self):
self.tan_btn = Button(self.buttons_2_functions_1_frm, text = "tan", height = 1, width = 5)
self.tan_btn.grid(row = 0,column = 0)
self.san_btn = Button(self.buttons_2_functions_1_frm, text = "san", height = 1, width = 5)
self.san_btn.grid(row = 0,column = 1)
self.coz_btn = Button(self.buttons_2_functions_1_frm, text = "coz", height = 1, width = 5)
self.coz_btn.grid(row = 1,column = 0)
def create_2_function_gui(self):
self.buttons_2_functions_2_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_2_frm.grid(row = 1, column = 0)
self.inverse_tan_btn = Button(self.buttons_2_functions_2_frm, text = "tan-1", height = 1, width = 5)
self.inverse_tan_btn.grid(row = 0,column = 0)
self.inverse_san_btn = Button(self.buttons_2_functions_2_frm, text = "san-1", height = 1, width = 5)
self.inverse_san_btn.grid(row = 0,column = 1)
self.inverse_coz_btn = Button(self.buttons_2_functions_2_frm, text = "coz-1", height = 1, width = 5)
self.inverse_coz_btn.grid(row = 1,column = 0)
def mode_change(self):
if self.modefunction == 1:
self.buttons_2_functions_1_frm.destroy()
self.modefunction = 2
self.buttons_2_functions_2_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_2_frm.grid(row = 1, column = 0)
self.create_2_function_gui()
else:
self.buttons_2_functions_2_frm.destroy()
self.modefunction = 1
self.buttons_2_functions_1_frm = Frame(self, width=50, height=30)#bg = "blue")
self.buttons_2_functions_1_frm.grid(row = 1, column = 0)
self.create_1_function_gui()
root = Tk()
root.title("booking system")
root.geometry("500x500")
root.configure(bg="white")
app = Calc(root)
root.mainloop()
In this program i want the time to continue on each button even if another is clicked, yet, time seems to stop on a button when another is click i any suggestions here?
from Tkinter import *
import os
import time
class Application(Frame):
##########################################################################
def my_timeDrag(self): # creates a timer starting at 5 min , counts down to 0 then repeats
min = 5
sec = 59
while sec <=60:
self.Button3.configure(text="{}:{}".format(min,sec))
self.Button3.update()
os.system('cls')
print min, "Minutes", sec, "Seconds"
time.sleep(1)
sec -= 1
if sec == 0:
min -= 1
sec = 59
elif min == 0:
min = 5
##########################################################################################
def my_timeBB(self): # creates a timer starting at 5 min , counts down to 0 then repeats
min = 4
sec = 59
while sec <=60:
self.Button1.configure(text="{}:{}".format(min,sec))
self.Button1.update()
os.system('cls')
print min, "Minutes", sec, "Seconds"
time.sleep(1)
sec -= 1
if sec == 0:
min -= 1
sec = 59
elif min == 0:
min = 4
#######################################################
def my_timeRB(self): # creates a timer starting at 5 min , counts down to 0 then repeats
min = 4
sec = 59
while sec <=60:
self.Button2.configure(text="{}:{}".format(min,sec))
self.Button2.update()
os.system('cls')
print min, "Minutes", sec, "Seconds"
time.sleep(1)
sec -= 1
if sec == 0:
min -= 1
sec = 59
elif min == 0:
min = 4
########################################################
def createButtons(self): # creats a button
self.Button1 = Button(self)
self.Button1["text"] = "Blue Buff"
self.Button1["fg"] = "Blue"
self.Button1["command"] = self.my_timeBB # suppose to implement countdown in button text when click.
self.Button1.pack({"side": "left"})
self.Button2 = Button(self)
self.Button2["text"] = "Red Buff"
self.Button2["fg"] = "Red"
self.Button2["command"] = self.my_timeRB
self.Button2.pack({"side":"right"})
self.Button2.pack(padx=50)
self.Button3 = Button(self)
self.Button3["text"] = " Dragon "
self.Button3["fg"] = "Pink"
self.Button3["bg"] = "Purple"
self.Button3["command"] = self.my_timeDrag
self.Button3.pack(side="bottom",pady=50)
self.Quit = Button(self)
self.Quit["text"] = "Quit"
self.Quit["command"] = self.quit
self.Quit.pack()
##############################################################
##############################################################
def __init__(self, master=None):
Frame.__init__(self, master) # initializes window
self.pack()
self.createButtons()
root = Tk()
root.title("Jungle Timer by BabyAchilles")
root.geometry("400x300")
app = Application(master=root)
root.mainloop()
Your problem is that Button from tkinter just only implement the command function whenever the user clicks on that button. Therefore, when the user clicks on another button, that command function will stop/terminate and change to the clicked button command function. That's the main reason why your timer stops!
There are two solutions for this problem:
The easiest way is to store your timer (such as Button1 minutes, secs, Button2 minutes, secs,...) as attributes and to use tkinter Label to display the timer for each of them on the interface instead of dealing your problem about the Button since the command function will always stop and change to another one whenever the user clicks on the buttons.
Another way to solve this problem is to use the .invoke() method in the Button widget to call back the command functions from previous clicked buttons. If you want to use this way, you can look up on this link about how this method works: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/button.html
P/S: I love League of Legends, too!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is my code demo for the timer, so check it out! I used .after() method for the root window. Also, I stored all my time data as an object attribute, so it's easier to access!
import tkinter
import time
DEFAULT_FONT = ('Helvetica',30)
class LoL_JungleTimer():
def __init__(self):
self._root_window = tkinter.Tk()
Dragon_button = tkinter.Button(master = self._root_window, text = 'Dragon', fg = 'purple', command = self._dragon_start)
BlueBuff_button = tkinter.Button(master = self._root_window, text = 'Blue Buff', fg = 'blue', command = self._blue_buff_start)
RedBuff_button = tkinter.Button(master = self._root_window, text = 'Red Buff', fg = 'red', command = self._red_buff_start)
self._blue_buff_label = tkinter.Label(master = self._root_window, text = '5:00', fg = 'blue', font = DEFAULT_FONT)
self._red_buff_label = tkinter.Label(master = self._root_window, text = '5:00', fg = 'red', font = DEFAULT_FONT)
self._dragon_label = tkinter.Label(master = self._root_window, text = '6:00', fg = 'purple', font = DEFAULT_FONT)
Dragon_button.grid(row = 0, column = 0, padx = 10, pady = 10)
BlueBuff_button.grid(row = 1, column = 0, padx = 10, pady = 10)
RedBuff_button.grid(row = 2, column = 0, padx = 10, pady = 10)
self._blue_buff_label.grid(row = 1, column = 1, padx = 10, pady = 10)
self._red_buff_label.grid(row = 2, column = 1, padx = 10, pady = 10)
self._dragon_label.grid(row = 0, column = 1, padx = 10, pady = 10)
self.drag_minute = 5
self.drag_second = 59
self.BB_minute = 4
self.BB_second = 59
self.RB_minute = 4
self.RB_second = 59
def run(self):
self._root_window.mainloop()
def _time_counter(self, minutes, seconds):
if seconds < 60:
seconds -= 1
if seconds == 0:
seconds = 59
minutes -= 1
return minutes, seconds
def _blue_buff_start(self):
self._blue_buff_label.configure(text = "{0}:{1:02d}".format(self.BB_minute,self.BB_second))
self._root_window.update()
self.BB_minute,self.BB_second = self._time_counter(self.BB_minute,self.BB_second)
self._root_window.after(1000, func = self._blue_buff_start)
def _dragon_start(self):
self._dragon_label.configure(text = "{0}:{1:02d}".format(self.drag_minute,self.drag_second))
self._root_window.update()
self.drag_minute,self.drag_second = self._time_counter(self.drag_minute,self.drag_second)
self._root_window.after(1000, func = self._dragon_start)
def _red_buff_start(self):
self._red_buff_label.configure(text = "{0}:{1:02d}".format(self.RB_minute,self.RB_second))
self._root_window.update()
self.RB_minute,self.RB_second = self._time_counter(self.RB_minute,self.RB_second)
self._root_window.after(1000, func = self._red_buff_start)
if __name__ == '__main__':
LoL_JungleTimer().run()