Search code examples
pythontkinterpositionmargin

how can i position frame right to left hasn't margin


enter image description here

i want to position right textbox to left then Logout Button position should not move any position '''

from tkinter import *

# container window
root = Tk()

# frame
frame = Frame(root)

# content of the frame
frame.text = Text(root)
frame.text.insert('1.0', 'Geeks for Geeks')

frame.text.pack_propagate(True)
# to add margin to the frame
frame.text.grid(row=0, column=1,
                pady=20)
# simple button
frame.quitw = Button(root)
frame.quitw["text"] = "Logout",
frame.quitw["command"] = root.quit
frame.quitw.grid(row=1, column=0, padx=100)
frame.quitw.pack_propagate(True)
root.mainloop()

'''


Solution

  • You can put the widgets in the same column:

    from tkinter import *
    
    # container window
    root = Tk()
    
    # frame
    frame = Frame(root)
    
    # content of the frame
    frame.text = Text(root)
    frame.text.insert('1.0', 'Geeks for Geeks')
    
    frame.text.pack_propagate(True)
    # to add margin to the frame
    frame.text.grid(row=0, column=1,
                    pady=20)
    # simple button
    frame.quitw = Button(root)
    frame.quitw["text"] = "Logout",
    frame.quitw["command"] = root.quit
    frame.quitw.grid(row=1, column=1, padx=100)
    frame.quitw.pack_propagate(True)
    root.mainloop()