在 Python 中设置按钮的位置? [英] Setting the position on a button in Python?

查看:167
本文介绍了在 Python 中设置按钮的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚编写了一个代码来创建一个窗口(使用 TKinter)并显示一个工作按钮.

I just wrote a code that creates a window (using TKinter) and displays one working button.

b = Button(master, text="get", width=10, command=callback)

但我想在这个下面有多个按钮.

But i would like to have multiple buttons underneath this one.

按钮的行列如何设置?我尝试添加 row = 0, column = 0, 但这不起作用.

How do you set the row and column of the button? I tried to add row = 0, column = 0, but that would not work.

谢谢

推荐答案

astynax 是对的.按照你给出的例子:

astynax is right. To follow the example you gave:

MyButton1 = Button(master, text="BUTTON1", width=10, command=callback)
MyButton1.grid(row=0, column=0)

MyButton2 = Button(master, text="BUTTON2", width=10, command=callback)
MyButton2.grid(row=1, column=0)

MyButton3 = Button(master, text="BUTTON3", width=10, command=callback)
MyButton3.grid(row=2, column=0)

应该创建 3 行按钮.使用 grid 比使用 pack 好很多.但是,如果您在一个按钮上使用网格并在另一个按钮上打包,它将不起作用并且您将收到错误消息.

Should create 3 row of buttons. Using grid is a lot better than using pack. However, if you use grid on one button and pack on another it will not work and you will get an error.

这篇关于在 Python 中设置按钮的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆