in Education by
I asked a question like this here: How to adjust Label in tkinter? But the events load up and eventually python can't handle the events, and it crashes. How to make this not happen?? Maybe because it's in a loop, so they overload? I can't figure out how to make it not crash. Here is my code: from tkinter import * from time import * print("""This is an app that basically you time the amount of time someone takes to fall from a cliff, then we will use an equation to tell you how high the cliff is. This is a recreation of the app Mark Rober created, by The way""") window = Tk() window.title("falling app") window.geometry("700x700") window.configure(bg = "sky blue") """We will use time import for this""" mins = 0 seconds = 0 secs = Label(window, text = seconds, font = ("verdana", 60)) secs.place(relx = 0.48, rely = 0.35, anchor = "nw") def start(): mins = 0 seconds = 0 while seconds != 60: sleep(1.00) seconds+= 1 secs.configure(text = seconds) if seconds == 60: mins = mins+1 seconds = 0 This line: secs.configure(text = seconds) is the culprit. Im sure of it. Thanks in advance!!!!!!!! Edit: This is what it looks like, it blanks out, and becomes unresponsive. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The reason the program hangs is because you've created an endless loop which prevents tkinter from ever being able to process events. Tkinter is single threaded, and can only work when it is able to process a steady flow of events. You've prevented that with this infinite loop: while seconds != 60: sleep(1.00) seconds+= 1 secs.configure(text = seconds) A quick fix is to call update in that loop. Your program will still freeze for one second, and then become active for just a few milliseconds before freezing again. That's a very inefficient way to write a tkinter program. The better way would be use use the after method to continually schedule your function to run once every second. There are probably dozens of not hundreds of examples of that technique on this site. In a nutshell it looks something like this: def update_clock() global mins, seconds seconds += 1 if seconds > 60: seconds = 0 mins += 1 secs.configure(text = seconds) window.after(1000, update_clock) You then call this function once in your start method, and it will continue to run every second until the program quits: def start(): global mins, seconds mins = 0 seconds = 0 update_clock()

Related questions

0 votes
    I have two Dataframes : DF1(That i've just resampled): Mi_pollution.head(): Sensor_ID Time_Instant ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how I can represent the equivalent of an Enum in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am trying to fit some (numpy) data into python skLearn modules, but keep getting error messages. When ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Convert pandas DateTimeIndex to Unix Time? (7 answers) Closed 3 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    Let's say I have the following code: from types import coroutine @coroutine def stop(): yield 1 async ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have multiple xlsx files with data in it that i want to import to separate dataframes in Python. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I used the function for gower distance from this link: https://sourceforge.net/projects/gower-distance- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to have root mean squared of gradient boosting algorithm but when I want to print it, I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm trying to do the Udacity mini project and I've got the latest version of the SKLearn library ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I want to get the values of col1 in 3 different columns with separate headers. Date/Time col1 0 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm working on a project which need these deep learning libraries - keras and tensorflow. Unfortunately, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm creating my first program on python. The objective is to get an output of trip cost. In the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
...