Issue with buttons not functioning after start of program

2024/11/21 19:36:24

I am new and learning python 3.6 and I've almost completed my first code project. After doing an exhaustive search to resolve my problem I have not been able to find the answer to what I am sure is a simple oversight.

Program premise: A user enters a URL and also clicks in a checkbox for the time frame to call the url. The user then clicks the start button and the program begins to open the url in a timeloop according to the checkbox(time) selected. This is working fine... however once the program has started the buttons are no longer active and do not work, they are not able to be clicked. I have used tkinter for the gui.

I am trying to keep 2 buttons active for the user. The Quit button, which quits the function of the program and the Exit button that exits and closes the program completely.

A point in the right direction would be appreciated.

Current sleep() code used:

def execute():
execute = urllib.request.urlopen(url.get()))def Time():
if CheckVar1.get() and url.get():
timeloop = True
Sec = 0
Min = 0
timeLoop = A
while timeLoop:Sec += 1execute()time.sleep(300)

I hope this helps make my question a little easier to follow. I believe that I might need to find another way to do what this is doing so that the loop allows the other parts of the program (buttons), to remain active so a user can Quit or Exit the program once it is running. Note: CheckVar1.get() is to verify if the checkbox has been selected for that time frame, there are 8 different time settings being used.

Answer

Your code indentation is wrong and maybe there are other issues too, but as your approach is essentially wrong, here is an example of how to call a fuction after some time in tkinter, without blocking the UI. This can be used as a kind of background processing, and it's simple:

import tkinter as tk
from tkinter import Tk, ttkdef some_action():# do what you want# ...print('Hi! Getting my urls here...')# but don't block with sleeps or infinite loops,# and thennext_check = get_your_check_interval() # somehow calculate or# retrieve this from# your vars or widgets,# using seconds# register for the next call of some_actionroot.after(next_check*1000, some_action)def get_your_check_interval():return 3 # just using 3 seconds now...root = Tk()start_button = ttk.Button(root, text='Start', command=some_action)
quit_button = ttk.Button(root, text='Quit', command=quit)start_button.pack(side=tk.LEFT)
quit_button.pack()
root.mainloop()

As you see the buttons remain responsive and you can quit the application. So I think you can solve your problem with the same technique.

https://en.xdnf.cn/q/120724.html

Related Q&A

explanation of C implementation pythons len function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

How to compare the attributes start with $ in 2 functions and display match or mismatch

My input file contain attributes if(match($OPTION_EnableDetails, "1") or match($OPTION_EnableDetails_juniper, "1")) {details($juniFileXferStatus,$juniFileXferTimeStamp,$juniFileXfer…

Python comparing elements in two lists

I have two lists:a - dictionary which contains keywords such as ["impeccable", "obvious", "fantastic", "evident"] as elements of the listb - sentences which cont…

Remove all keys that have values of N/A, -, or empty strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Sorting algorithms more efficient than bubble sort [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

How can I return the odd numbers of a list, using only recursion in Python? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

TypeError: int object is not iterable; Python 2.7

Here is my code:def numbers_in_lists(string):num = int(string)l = list(num)return lstring = 543987When i run it:print numbers_in_lists(string)I have the following error:l = list(num) TypeError: int obj…

Python: Are `hash` values for built-in numeric types, strings standardised?

I came to this question while pondering about the ordering of set, frozenset and dict. Python doesnt guarantee any ordering, and any ordering is coupled to the hash value at some level. But is the hash…

How to create a sample django project?

This doesnt work for me.$ python django-admin.py startproject myprojectI am running a ubuntu virtual m/c on my windows system. By default ubuntu 12.04 comes with python 2.7.3 so I am using that only I …

Why elif statement instead of if statement? [duplicate]

This question already has answers here:Difference between multiple ifs and elifs?(9 answers)Why we use if, else if instead of multiple if block if the body is a return statement(13 answers)Closed 7 ye…