Shihab
Shihab

Reputation: 112

How to make fixed position with the window of a widget in tkinter?

I was working on a project and I want to make fixed position with window size I mean if the window resized the position of that widget will be increase \ decrease .

Help I made this : enter image description here

but If I increase size of the window look :

enter image description here

the button will be in the same position 😢

Code :

from tkinter import *
from tkinter import ttk
import os

edt_win = Tk()
edt_win.geometry("1280x720")
edt_win.title("Tkinter Editor")
edt_win.minsize(width=900, height=700)
mainfont = ("comic sans ms",10,"bold")

add_obj_menu_frm = Frame(width=200,height=200,relief=SUNKEN,borderwidth=4)
add_obj_menu_frm.pack(side=LEFT,fill=BOTH,ipady=200,pady=50)

def add_obj_layout():
    add_btn = ttk.Button(master=edt_win,text="Add")
    add_btn.pack(side=BOTTOM,fill=BOTH)
    add_btn.place(x=8,y=680)

add_obj_layout()
edt_win.mainloop()

Any Help will be in the heart ♥️

Upvotes: 1

Views: 2122

Answers (2)

acw1668
acw1668

Reputation: 47173

You can use place() for both the frame and the button:

add_obj_menu_frm = Frame(width=200, height=200, relief=SUNKEN, borderwidth=4)
#add_obj_menu_frm.pack(side=LEFT, fill=BOTH, ipady=200, pady=50)
add_obj_menu_frm.place(x=0, y=50, width=200, relheight=1, height=-100) # 50px top and bottom margins

def add_obj_layout():
    add_btn = ttk.Button(master=edt_win, text="Add")
    add_btn.pack(side=BOTTOM, fill=BOTH)
    #add_btn.place(x=8, y=680)
    add_btn.place(x=8, rely=1, y=-40) # 40px from the bottom

Upvotes: 1

oskros
oskros

Reputation: 3305

You are calling the .place() function for your button which fixes the position so it no longer rescales with the application. Try removing that part - the pack() method anyway takes care of drawing your button for you.

Upvotes: 1

Related Questions