A
A
Andrei1penguin12021-05-08 01:16:33
Python
Andrei1penguin1, 2021-05-08 01:16:33

How to align button in width?

Good day, I'm trying to align the button to the center of the parent block using pos_hint: (0.5, 0.5)
But the button is only aligned vertically, horizontally nailed to the left.
Please tell me, is it possible to align the button in kivy to the center of the widget?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrei1penguin1, 2021-05-08
@Andrei1penguin1

I set the ID for the parent element, pulled out size[0] through it, that is, the width of the parent element, and with further simple manipulations I set the button to equal indents through pos

C
CLlPPER, 2021-05-08
@CLlPPER

from tkinter import *  # Use this if use python 3.xx
#from Tkinter import *   # Use this if use python 2.xx
a = Button(text="Center Button")
b = Button(text="Top Left Button")
c = Button(text="Bottom Right Button")

a.place(relx=0.5, rely=0.5, anchor=CENTER)
b.place(relx=0.0, rely=0.0, anchor=NW)
c.place(relx=1.0, rely=1.0, anchor=SE)
mainloop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question