ttk используется для всех кнопок. Кнопка «отключить» работает, когда «Button1» и «Button2» находятся в tk, но не работает, когда используется ttk. Как это можно решить для кода?
import tkinter as tk
import tkinter.ttk as ttk
fenster = tk.Tk()
fenster.title("Window")
canvas = tk.Canvas(fenster,bg="white",width=700, height=410, highlightthickness=0)
canvas.pack()
def switch1():
if b1["state"] == "normal":
b1["state"] = "disabled"
else:
b1["state"] = "normal"
def switch2():
if b3["state"] == "normal":
b3["state"] = "disabled"
else:
b3["state"] = "normal"
#--Buttons
b1 = ttk.Button(canvas, text="Button1") #works when tk is used
canvas.create_window(5, 5, window=b1, anchor=tk.NW)
b3 = ttk.Button(canvas, text="Button2") #works when tk is used
canvas.create_window(5, 100, window=b3, anchor=tk.NW)
b2 = ttk.Button(canvas, text="disable", command=switch1)
canvas.create_window(100, 5, window=b2, anchor=tk.NW)
b4 = ttk.Button(canvas, text="disable", command=switch2)
canvas.create_window(100, 100, window=b4, anchor=tk.NW)
fenster.mainloop()
b1.state(('!disabled' if 'disabled' in b1.state() else 'disabled',))
вswitch1()
. Аналогично относится кswitch2()
. - person acw1668   schedule 31.01.2020