1. Rossz megoldás.
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry('300x200')
self.style = ttk.Style()
self.button = ttk.Button(self, text="Kattints ide",
command=self.start)
self.button.pack(pady=20)
def start(self):
self.gomb_szint_modosit('red')
# A paramétert közvetlenül adjuk át az after() metódusnak.
# A "black" paraméter a gomb_szint_modosit() függvényhez tartozik
self.after(3000, self.gomb_szint_modosit('black'))
def gomb_szint_modosit(self, color):
self.style.configure('TButton', foreground=color)
print(color)
if __name__ == "__main__":
app = App()
app.mainloop()
Ez így a PyCharm szerint nem jó, nem pontos!
2. Rossz megoldás, bár a hiba kisebb súlyú.
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry('300x200')
self.style = ttk.Style()
self.button = ttk.Button(self, text="Kattints ide",
command=self.start)
self.button.pack(pady=20)
def start(self):
self.gomb_szint_modosit('red')
# A paramétert közvetlenül adjuk át az after() metódusnak.
# A "black" paraméter a gomb_szint_modosit() függvényhez tartozik
self.after(3000, lambda: self.gomb_szint_modosit('black'))
def gomb_szint_modosit(self, color):
self.style.configure('TButton', foreground=color)
print(color)
if __name__ == "__main__":
app = App()
app.mainloop()
3. Nagyon bosszantott a dolog, mert szinte hetente belefutottam ilyen és hasonló hibába.
Hónapok óta nyaggattam a Gemini -t, de PyCharm hibáztatásnál nem jutottunk tovább. Most sem sikerült elsőre javítani, ezért megkértem a Geminit, hogy gondolkodjon angolul és az angol nyelvű dokumentációkban nézzen utána. Végre itt a pofon egyszerű hibajelzés mentes megoldás. Hurrá!
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry('300x200')
self.style = ttk.Style()
self.button = ttk.Button(self, text="Kattints ide",
command=self.start)
self.button.pack(pady=20)
def start(self):
self.gomb_szint_modosit('red')
# A paramétert közvetlenül adjuk át az after() metódusnak.
# A "black" paraméter a gomb_szint_modosit() függvényhez tartozik
self.after(3000, self.gomb_szint_modosit, 'black')
def gomb_szint_modosit(self, color):
self.style.configure('TButton', foreground=color)
print(color)
if __name__ == "__main__":
app = App()
app.mainloop()
Ezt is a Linux Mint operációs rendszeren írtam.
Layco
Nincsenek megjegyzések:
Megjegyzés küldése