DuckyPolice alt
DuckyPolice alt

Reputation: 21

why isnt python tkinter box going all the way to the bottom

in tkinter I'm making a game called pet clicker. (here is a video of it so you can get an idea what your dealing with: https://www.youtube.com/watch?v=06rdvx9-O7I) I'm trying to make a sidebar on the right side where you can get pets, but it wont go all the way to the bottom no matter how far down I put the coordinates. I have tried using it with a different pc and nothing changed. the video doesn't show the project with the sidebar but it shows what the project does and a little bit of the code. can I get some code that will add a background sidebar on the right of the screen that I can put buttons on?

CODE:

from random import randint 
from tkinter import * 
from tkinter import Tk, Text, Canvas, Frame, BOTH 
import time 
import tkinter.font as tkFont

global text
global top
top = Tk()
top.geometry("1440x800")
check = 0
coin = PhotoImage(file=r"bigcoin.png")
global coins
coins = 0
text = Text(top, height=1, width=9)
coinsfont = tkFont.Font(family="Arial", size=30, weight="bold", 
slant="roman")
text.pack()
text.configure(font=coinsfont)

text.insert(1.0, str(coins))
sidebar = Canvas(top, width=2000, height=900)
sidebar.create_rectangle(2200, 0, 2600, 1555, fill="#682000", 
outline='red')
sidebar.pack()


def buttonpress1():
    coinsys()
    global b1
    b1 = Button(top, text="Coin", image=coin, command=buttonpress2)
    b1.place(x=randint(100, 1400), y=randint(100, 800))
    if check == 1:
        b2.destroy()
    top.mainloop()


def buttonpress2():
    coinsys()
    b1.destroy()
    global b2
    global check
    check = 1
    b2 = Button(top, text="Coin", image=coin, command=buttonpress1)
    b2.place(x=randint(100, 1400), y=randint(200, 800))
    text.update()


def coinsys():
    update()
    global coins
    coins += 1
    print("coins: ", coins)


def update():
    try:
        text.delete(1.0, "end")
except:
    pass

    if coins == 1:
        text.insert(1.0, " coin")
    else:
        text.insert(1.0, " coins")
    text.insert(1.0, str(coins))


buttonpress1()

Upvotes: 0

Views: 60

Answers (2)

toyota Supra
toyota Supra

Reputation: 4595

Try this.

  • In line 32, I make a smaller rectangle, but you can suit your needs. sidebar.create_rectangle(122, 0, 560, 155, fill="#682000",outline='red') Don't set values too high.
  • Line 33, I added pack to set to right. sidebar.pack(anchor='e')

That all. You're ready to go. Btw, I didn't install PhotoImage.

Output:

enter image description here

Upvotes: 0

DuckyPolice
DuckyPolice

Reputation: 44

it is the textbox that shows the coins that is taking up that whole row. try using grid and not pack.

Upvotes: 1

Related Questions