Hello everyone
How can i make the button be on the left side or right side please
Part of the code

Button(self, text = "start", command = self.launch).grid(row = 7, column = 0, columnspan = 1,)

Thanks in advance

Dani AI

Generated

Several valid routes are already on the thread: suggested using pack, pointed out sticky anchoring, and showed a spacer-label trick. If the existing layout uses grid, a cleaner approach is to give one column a positive weight so it expands, then place the button in an adjacent column and anchor it left or right — this avoids invisible spacer widgets and behaves well on window resize.

A compact example that right-aligns the button using grid column weights:

import tkinter as tk

root = tk.Tk()
frame = tk.Frame(root)
frame.pack(fill='x')            # manage frame with pack, grid inside it is fine

frame.grid_columnconfigure(0, weight=1)   # column 0 expands
btn = tk.Button(frame, text='Start', command=lambda: None)
btn.grid(row=7, column=1, sticky='e', padx=6)
root.mainloop()

Notes and troubleshooting:

  • To left-align instead, make column 1 the expanding one (weight=1) and place the button in column 0 with sticky='w'.
  • Call grid_columnconfigure on the container that holds the grid (here frame). weight controls how extra space is distributed; a column with weight>0 grows when the window expands.
  • Avoid mixing pack and grid in the same parent widget — using a Frame (as above) is the safe way to combine them.
  • If the button needs later access, keep a reference (don’t chain creation and .grid() on the same line).
  • padx/pady add spacing; sticky anchors the widget inside its grid cell.

This keeps the layout predictable, rescales nicely, and is usually simpler than spacer widgets while giving the same left/right placement behavior.

Recommended Answers

All 3 Replies

assuming this is tkinter, you could use pack instead of grid and -side left or -side right.

You can also use the stick attribute

Button(self,text="Start",command=self.launch).grid(row = 7, column = 0, columnspan = 1, sticky=E)

But sticky attribute can be really messy. Just experiment with the positioning. Other values for sticky are N and W and S. You can also use them in combination

You could potentially us a label as a spacer:

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root['bg'] = 'yellow'

# use label as spacer, match background color
spacer = tk.Label(root, width=20, bg='yellow')
spacer.grid(row=1, column=1)

button = tk.Button(root, text="Button1")
# puts button to the right of label spacer
button.grid(row=1, column=2)

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.