i try to bring those 2 buttons i a line under the dropboxes –
But as you can see in the picture – the button are not in the same line. This is part of my code where i am setting the grid for the output:
JavaScript
x
9
1
myB = Button(root,text="Generate",padx=20,pady=10,command=show)
2
myB2 = Button(root,text="Reset",padx=20,pady=10,command=reset)
3
4
drop.grid(row=0,column=0, columnspan=2)
5
drop2.grid(row=1,column=0, columnspan=2)
6
drop3.grid(row=2,column=0, columnspan=2)
7
myB.grid(row=3,column=0)
8
myB2.grid(row=4,column=1)
9
Any ideas why this is not working as expected?
Advertisement
Answer
In order to match your image the code needs to look like this.
JavaScript
1
17
17
1
root.rowconfigure(0, weight = 1)
2
root.columnconfigure(0, weight = 1)
3
root.rowconfigure(1, weight = 1)
4
root.columnconfigure(1, weight = 1)
5
root.rowconfigure(2, weight = 1)
6
7
myB = Button(root, text = "Generate", padx = 20, pady = 10, command = show)
8
myB2 = Button(root, text = "Reset", padx = 20, pady = 10, command = reset)
9
10
# sticky needed for resizing with window
11
drop.grid(row = 0, column = 0, columnspan = 2, sticky = tk.NSEW)
12
drop2.grid(row = 1, column = 0, columnspan = 2, sticky = tk.NSEW)
13
drop3.grid(row = 2, column = 0, columnspan = 2, sticky = tk.NSEW)
14
# This will make buttons 'float' otherwise un-rem sticky
15
myB.grid(row = 3, column = 0) #, sticky = tk.NSEW)
16
myB2.grid(row = 3, column = 1) #, sticky = tk.NSEW)
17