I am using multiple buttons in my code and they come among each other. I want them to be side by side, I have checked here: Setting the position on a button in Python? and have try'd the solution of that question,
However, I use .pack and I need to change it to grid? This is what I've got:
#import tKinter
import sys
from tkinter import *
def mhello():
mlabel1 = Label(window,text = 'Hello we have to start / да започне').pack()
def mhello1():
mlabel2 = Label(window,text = 'Hello we have to stop / да спре').pack()
def mhello2():
mlabel3 = Label(window,text = 'Hello we have to add / да добавите').pack()
#create new window
window = Tk()
#set window title
window.title("Изпитване програмата")
#set window size
window.geometry("700x200")
#menu start
def donothing():
filewin = Toplevel(window)
print("Welcome to my test program, XOXO Katherina")
mlabel5 = Label(window,text = 'Welcome to my test program, XOXO Katherina').pack()
def leave():
sys.exit(0)
menubar = Menu(window)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=window.destroy)
menubar.add_cascade(label="File", menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About...", command=donothing)
menubar.add_cascade(label="Help", menu=helpmenu)
window.config(menu=menubar)
#menu ends
#buttons here
mlabel = Label(window,text = 'My label').pack()
mbutton = Button(window,text = 'Start',command = mhello, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3').pack()
mbutton1 = Button(window,text = 'Stop',command = mhello1, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3').pack()
mbutton2 = Button(window,text = 'Add',command = mhello2, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3').pack()
#end buttons
#draw the window start application
window.mainloop()
also have try'd to change the buttons to:
#buttons here
mlabel = Label(window,text = 'My label').pack()
mbutton = Button(window,text = 'Start',command = mhello, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3')
mbutton.grid(row=0, column=0)
mbutton1 = Button(window,text = 'Stop',command = mhello1, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3')
mbutton1.grid(row=1, column=0)
mbutton2 = Button(window,text = 'Add',command = mhello2, fg = 'black',bg = 'red', height = '3',width = '5',bd = '3')
mbutton2.grid(row=2, column=0)
#end buttons