0

Hello I do a cookie clicker. When the code is runnig, i see the button but the cookie image doesn't appear on its. Also, when i click on the button, nothing is happening. Here is the script:

from tkinter import *
from tkinter import Button

marron = "#ce6242"
c_cookie = "#8c5945"
class Cookie_clicker:

    def __init__(self):

        self.score = None
        self.cookie_button = None
        self.root = Tk()
        self.root.geometry("720x440")
        self.root.config(background=marron)
        self.nbr_click = 0
      
        self.f1 = Frame(self.root, bg=marron, highlightthickness=0)
        self.f1.pack()

        self.create_w()

    def command_button(self):
        self.nbr_click += 1
        self.maj_label_score()

    def create_w(self):
        self.create_cookie_button()
        self.create_label_score()

    def create_cookie_button(self):
        width = 300
        height = 300
        image = PhotoImage(file="/home/noam/PycharmProjects/pythonProject/Images/cookie.png").zoom(10).subsample(5)
        cookie_button = Button(self.f1, height=height, width=width, bg=marron, command=self.command_button())
        cookie_button.config(image=image)
        cookie_button.pack()

    def create_label_score(self):
        self.score = Label(self.f1, text="0 click", width=10)
        self.score.pack()

    def maj_label_score(self):
        self.score = str(self.nbr_click), "click"

cooki = Cookie_clicker()
cooki.root.mainloop()```
Noam
  • 3
  • 4
  • "on its" **what**? Also - typo? You want `command=self.command_button` as the parameter, not calling the function – OneCricketeer Apr 18 '22 at 21:42
  • Sorry, I'm French and I don't speak English very well but I didn't understand you want that I put this in what parameters? When i remove tuples nothing change. – Noam Apr 18 '22 at 22:07
  • @OneCricketeer: I'm sure the OP meant "…but the cookie image doesn't appear on **it**." – martineau Apr 18 '22 at 22:16
  • Noam: He meant the you're *calling* function (and using the value it returns, `None`, as the argument value using `command=self.command_button()` — not passing it as a parameter which `command=self.command_button` would do. – martineau Apr 18 '22 at 22:19

0 Answers0