Have a look at this code example:
from tkinter import *
root = Tk()
def createbuttons ():
texts = ["Do this", "Do that", "Hide"]
global btns
btns = []
for btn in texts:
b = Button(root, text= btn, width=20)
b.pack(side=LEFT, padx=15)
btns.append(b)
btns[2].config(command=hide)
def hide ():
btns[0].pack_configure(padx=(15,105))
btns[1].destroy()
btns[2].pack_configure(padx=(105,15))
createbuttons()
root.mainloop()
Everything works fine for me, but it seems like a newbie solution to the problem. Since the button width is a mix of pixles and character width I didn't know how many pixles I needed to add, but after trying it like 10 times it looked good with 210 pixles (105 + 105).
My question is: is there a better way to do this? Or at least a way to know how many pixles a button takes up?
Thanks in advance!