【问题标题】:alignment of buttons in tkinter moduletkinter 模块中按钮的对齐方式
【发布时间】:2019-05-31 22:36:40
【问题描述】:

我正在制作一个基于 tkinter 模块的 GUI 应用程序 我想以 2x2 布局的形式对齐按钮,但它没有对齐按钮 相反,它将按钮对齐一行

我只想以 2x2 布局的形式对齐问题、返回、状态、默认值。 学分按钮应该在右下角

编码:

from tkinter import *
a = Tk()    # a is the window variable
a.title('Doodle Engine powered Library management')
a.geometry('580x300')
Label(text = "Library ManageMent", bg = "grey", width = "55", height = "1", font = ("Calibri", 13)).pack(side = "top")
bt_issue = Button(a,text = 'Issue',width = 9, height = 1, )
bt_issue.pack(padx=25, pady=10, side=LEFT)      #sets button issue
bt_return = Button(a,text = 'Return',width = 9, height = 1, )
bt_return.pack(padx=25, pady=20, side=LEFT)     #sets button return 
bt_status = Button(a,text = 'Status',width = 9, height = 1, )
bt_status.pack(padx=25, pady=20, side=LEFT)     #sets button status 
bt_default = Button(a,text = 'Defaulters',width = 9, height = 1, )
bt_default.pack(padx=25, pady=20, side=LEFT)    #sets button defaulter 
bt_credits = Button(a,text = 'Credits',width = 9, height = 1, )
bt_credits.pack()    #sets button credit 
a.mainloop()     #sets the GUI running

我通过 anaconda 发行版在 win 10 上使用 python 3.7.0

【问题讨论】:

标签: python button layout tkinter


【解决方案1】:

试试这个:

from tkinter import *
a = Tk()    # a is the window variable
a.title('Doodle Engine powered Library management')
a.geometry('580x300')
Label(text = "Library ManageMent", bg = "grey", width = "55", height = "1", font = ("Calibri", 13)).grid(row=0, column=0, columnspan=2)
bt_issue = Button(a,text = 'Issue',width = 9, height = 1, )
bt_issue.grid(padx=25, pady=10, row=1, column=0)      #sets button issue
bt_return = Button(a,text = 'Return',width = 9, height = 1, )
bt_return.grid(padx=25, pady=20, row=1, column=1)     #sets button return
bt_status = Button(a,text = 'Status',width = 9, height = 1, )
bt_status.grid(padx=25, pady=20, row=2, column=0)     #sets button status
bt_default = Button(a,text = 'Defaulters',width = 9, height = 1, )
bt_default.grid(padx=25, pady=20, row=2, column=1)    #sets button defaulter
bt_credits = Button(a,text = 'Credits',width = 9, height = 1, )
bt_credits.grid(row=3, column=1)    #sets button credit
a.mainloop()     #sets the GUI running

【讨论】:

  • 恭喜 Partho63 得到了理想的输出
猜你喜欢
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 2019-02-04
  • 2021-01-20
  • 1970-01-01
  • 2020-03-11
  • 1970-01-01
  • 2022-01-05
相关资源
最近更新 更多