0

Main code:

import tkinter as tk
import time as t
import threading as th

count = 0
cursors = 0
cursorprice = 20


def addcookie():
    global count, sent
    count += 1
    sent = "You own " + str(count) + " cookies"
    c['text'] = sent


def addcursor():
    global cursorprice, count, cursors
    if count >= cursorprice:
        count -= cursorprice
        cursorprice += 10
        cursors += 1
        sent = "You own " + str(cursors) + " cursors"
        cursor['text'] = sent
        btn2['text'] = "Press for cursors" + "Price:" + str(cursorprice)
        sent = "You own " + str(count) + " cookies"
        c['text'] = sent
    else:
        btn2['text'] = "Not enough cookies!"
        t.sleep(1)
        btn2['text'] = "Press for cursors " + "Price:" + str(cursorprice)
        sent = "You own " + str(count) + " cookies"
        c['text'] = sent

def Ccheck():
    while True:
        t.sleep(10)
        for i in range(cursors):
            addcookie()


t1 = th.Thread(target=Ccheck)
t1.start()

root = tk.Tk()
root.title("Cookie Clicker Replica")
root.geometry('1920x1080')

btn = tk.Button(root, text="Press for Cookies", width=30, height=2, bg='brown', command=addcookie)
btn.place(x=0, y=0)

btn2 = tk.Button(root, text="Press for cursors" + "Price:20", width=30, height=2, command=addcursor)
btn2.pack(side='left', padx=10, pady=20)

c = tk.Label(root, text="You own 0 cookies")
cursor = tk.Label(root, text="You own 0 cursors")
skipline = tk.Label(root, text=" ")

btn.pack()
c.pack()
skipline.pack()
btn2.pack()
cursor.pack()

root.mainloop()

The .place() and .pack() functions both don't work on my button attributes I've tried everything like padx, ipadx, x, relx, and nothing works. I'm trying to line up the buttons close to the left side

I literally copied a code online and it works perfectly fine, so I copied its format and still failed The code online and how it should look like

import tkinter as tk

app = tk.Tk()
app.geometry('300x300') 

labelA = tk.Label(app, text = "Label (0, 0)", fg="blue", bg="#FF0")
labelB = tk.Label(app, text = "Label (20, 20)", fg="green", bg="#300")
labelC = tk.Label(app, text = "Label (40, 50)", fg="black", bg="#f03")
labelD = tk.Label(app, text = "Label (0.5, 0.5)", fg="orange", bg="#0ff")

labelA.place(x=0, y=0)
labelB.place(x=20, y=20)
labelC.place(x=40, y=50)
labelD.place(relx=0.5, rely=0.5)

app.mainloop()

How it should look like is that every single attribute is placed according to the coordinates provided

How my code looks like: the x and y values simply don't work

GR_ Gamer
  • 7
  • 1
  • 1
  • Probably try `grid` – TheRavenSpectre May 21 '22 at 13:51
  • When you do `widget.place(...` you tell the widget to be used by the geometry manager *place*, when you use `.pack()` after you give that widget to another geometry manager. Thats why your initial keywords have no effect. Remove the `.pack...` lines and see what happens. Since you seem a beginner, [you may find this Q&A helpful](https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506) – Thingamabobs May 21 '22 at 13:52
  • 1
    Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community May 21 '22 at 14:51

1 Answers1

0
btn2 = tk.Button(root, text="Press for cursors" + "Price:20", width=30, height=2, command=addcursor)
btn2.pack(side='left', padx=10, pady=20)

Right here you, packed the second button instead of place, it appears to align correctly by changing button 2 to:

btn2 = tk.Button(root, text="Press for cursors" + "Price:20", width=30, height=2, command=addcursor)
btn2.place(x=0, y=0)

All I did was change .pack to .place and copied coordinates.

martineau
  • 119,623
  • 25
  • 170
  • 301
dantrr
  • 1
  • 3