[英]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 .我正在做一个项目,我想用窗口大小固定位置我的意思是如果窗口调整大小,该小部件的位置将增加\\减少。
but If I increase size of the window look :但是如果我增加窗口的大小,请看:
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 ♥️任何帮助都会在心中♥️
You are calling the .place()
function for your button which fixes the position so it no longer rescales with the application.您正在为您的按钮调用
.place()
函数,该函数修复了位置,因此它不再随应用程序.place()
。 Try removing that part - the pack()
method anyway takes care of drawing your button for you.尝试删除该部分 -
pack()
方法无论如何都会为您绘制按钮。
You can use place()
for both the frame and the button:您可以对框架和按钮使用
place()
:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.