I am just learning python, when i click on the button, it open calc, but the button remain pressed why?
I want the button to be released after the calc is opened
The button remains pressed until you close calc. That’s because the & symbol is missing in os.system(). I’ve tried this code on Linux, but should work on Windows too.
import tkinter as tk
import os
r = tk.Tk()
def Opencalc():
os.system("kate&")
r.title('Open calc')
button = tk.Button(r, text='Open', width=25, command=Opencalc, activebackground="red")
button.pack()
r.mainloop()
I don’t have calc.exe installed. The program hangs on os.system("calc.exe"), to check change it to print("calc.exe") and you’ll see it doesn’t hang on the button.
Try using subprocess and change to the calc.exe folder
Actually no, this wouldn’t work, cmd.exe does not have a “send to background” syntax like this. The subprocess version would probably not work either since it is blocking.
@Gagandeep What version of Windows are you using? Your code runs correctly on my Windows 10 machine, and the button correctly returned to unpressed state after calc is launched.