如何使用网格在Python中居中按钮?
问题描述:
我想使AND和OR按钮移动到窗口的中心位置,但我找不到任何合适的方法来这样做。 此外,该标签不会居中。 我不想用包()如何使用网格在Python中居中按钮?
from Tkinter import *
root = Tk()
root.title("BITWISE & and |")
Label(root,text='This program will calculate BITWISE AND OR',relief='ridge',font='times 20 bold italic',bg='red',fg='white').grid(row=0,columnspan=5)
Label(root, text='Enter 1st Bit ').grid(row=1, column=0)
e1 = Entry(root)
e1.grid(row=1, column=1)
Label(root, text='Enter 2nd Bit').grid(row=2)
e2 = Entry(root)
e2.grid(row=2, column=1)
def andr():
a = int(e1.get())
b = int(e2.get())
an = a & b
Label(root, text='The \'AND\' of the above Bits is = ' + str(an)).grid(row=5)
def ors():
a = int(e1.get())
b = int(e2.get())
o = a | b
Label(root, text='The \'OR\' of the above Bits is = ' + str(o)).grid(row=5)
Button(root, text="AND", command=andr).grid(row=3)
Button(root, text="OR", command=ors).grid(row=4)
root.mainloop()