为什么 python tkinter box 没有一直到底部
why isnt python tkinter box going all the way to the bottom
在 tkinter 中,我正在制作一款名为 Pet Clicker 的游戏。 (这里有一个视频,所以你可以了解你在处理什么:https://www.youtube.com/watch?v=06rdvx9-O7I)我正在尝试在右侧制作一个侧边栏,你可以在那里获得宠物,但它不会一直到底部,无论我把坐标放多远。我试过在另一台电脑上使用它,但没有任何改变。该视频没有显示带有侧边栏的项目,但它显示了项目的作用和一些代码。我能得到一些代码,在屏幕右侧添加一个背景边栏,我可以在上面放置按钮吗?
代码:
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()
是显示硬币的文本框占据了整行。尝试使用网格而不是打包。
在 tkinter 中,我正在制作一款名为 Pet Clicker 的游戏。 (这里有一个视频,所以你可以了解你在处理什么:https://www.youtube.com/watch?v=06rdvx9-O7I)我正在尝试在右侧制作一个侧边栏,你可以在那里获得宠物,但它不会一直到底部,无论我把坐标放多远。我试过在另一台电脑上使用它,但没有任何改变。该视频没有显示带有侧边栏的项目,但它显示了项目的作用和一些代码。我能得到一些代码,在屏幕右侧添加一个背景边栏,我可以在上面放置按钮吗?
代码:
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()
是显示硬币的文本框占据了整行。尝试使用网格而不是打包。