Hi, I'm trying to put sleep action on my program, but I would like program to sleep after I (as user)click and when he changes the picture on the button. and I don't know where to put it.
please help

this is example of code :)

import tkinter as tk
from functools import partial
def klik(n):
root = tk.Tk()
frame1 = tk.Frame(root)
frame1.pack(side=tk.TOP, fill=tk.X)
karirano = tk.PhotoImage(file="kari.GIF")
s = list(tk.PhotoImage(file="%d.GIF" % (i+1)) for i in range(4))
button = list()
for i in range(4):
    button.append(tk.Button(frame1, image=karirano, command=partial(klik, i)))

Recommended Answers

All 11 Replies

don't see how I can put that in my code

Why do you want your program to sleep ? You program does nothing but wait between clicks, isn't that sufficient ? If you add a sleep() somewhere, the gui will be unresponsive while the program sleeps.

I'd like to make that when 1 or 2 button's are pressed, others cant be pressed for some time

Then you should set their state to disabled.

commented: indeed +13

I tried, but when I started program, I got this message:

button[n].config(state= disabled)
NameError: global name 'disabled' is not defined

NameError: global name 'DISABLED' is not defined

you left out module name tk.disabled if name is corect.

ok, but I want to disable all buttons for 5sec, and then enable them all again. how can i do that?

You set after timer to call back then the buttons_enable function.

? what

? what

Set an after timer event five seconds from disabling buttons to re-enable the buttons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.