pythonjam的用法_python-3.x – 在Tkinter中使用Anchor

对于你想要做的事情,网格几何似乎是一个更好的主意,你可以显式地编码项目的位置,而不是让包几何隐式地确定它将去往何处.

另一个改进,就是拥有一个Frame,你可以在其中放置每个专辑Button.

我编辑了你的代码:

from tkinter import *

from tkinter import messagebox as box

def main_menu():

window = Tk()

window.title('Juke Box')

window.geometry('800x480')

window.configure(background = 'black')

label = Label(window, text = 'Juke-Box', fg = 'light green',

bg = 'black', font = (None, 30), height = 2)

label.pack(side = TOP)

gridFrame = Frame(window, bg='black') # New frame to store buttons

# Grid uses sticky instead of anchor, but in this scenario it is not really necessary

# I have left it in case you need it for some other reason

Jam = Button(gridFrame, text = 'The Jam', width = 25, height = 2)

Jam.grid(row=0, column=0, pady = 10, padx = 25, sticky=W)

Roses = Button(gridFrame, text = 'The Stone Roses', width = 25, height = 2)

Roses.grid(row=1, column=0, pady = 10, padx = 25, sticky=W)

Smiths = Button(gridFrame, text = 'The Smiths', width = 25, height = 2)

Smiths.grid(row=2, column=0, pady = 10, padx = 25, sticky =W)

Wedding = Button(gridFrame, text = 'The Wedding Pressent', width = 25, height = 2)

Wedding.grid(row=3, column=0, pady = 10, padx = 25, sticky =W)

Blondie = Button(gridFrame, text = 'Blondie', width = 25, height = 2)

Blondie.grid(row=4, column=0, pady = 10, padx = 25, sticky =W)

Clash = Button(gridFrame, text = 'Clash', width = 25, height = 2)

Clash.grid(row=5, column=0, pady = 10, padx = 25, sticky =W)

Madness = Button(gridFrame, text = 'Madness', width = 25, height = 2)

Madness.grid(row=0, column=1, pady = 10, padx = 25, sticky =N)

Pistols = Button(gridFrame, text = 'The Sex Pistols', width = 25, height = 2)

Pistols.grid(row=1, column=1, pady = 10, padx = 25, sticky =N)

gridFrame.pack(side=BOTTOM)

# Place it a the bottom or top or wherever you want it to go

window.mainloop()

main_menu()

以下是网格几何图形的截图:

这是你想要的吗?

希望它能帮助^^

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值