I am trying to create a GUI for a project. The code for which is below. I have a question regarding scalability. In my script I get Tkinter to display the GUI in fullscreen. However due to the nature of relx and rely in place it gets the label or button to start at the relative x and y positions. However this will mean on a different screen it won't look the same. For instance as relx and rely dictate where the widget starts (not the middle), every time the screen size is changed the appearance changes. I have shown two images which I think display my point. On the left image I have managed to position the widget so its in the middle, however due to the nature of where the widget starts when shrunk the close widget is no longer in the middle. Note it still starts at the same relx and rely but is no longer in the middle.
Essentially is there a way to make it scalable so it appears the same regardless of the size of window. Could this be done by making sure the relx and rely dictate the position of the middle not start of the widget?
from tkinter import *
import tkinter.font as tkFont
root = Tk()
root.title("N Body Simulation")
def exitclick():
root.destroy()
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.master = master
pad = 3
self._geom = '200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth() - pad, master.winfo_screenheight() - pad))
master.bind('<Escape>', self.toggle_geom)
def toggle_geom(self, event):
geom = self.master.winfo_geometry()
print(geom, self._geom)
self.master.geometry(self._geom)
self._geom = geom
frame = Frame(root)
frame.pack()
fontStyle = tkFont.Font(family="Lucida Grande", size=20)
text_intro = "This is the GUI for the N-Body simulation, from here you can change the plents and the initial conditions"
label = Label(root, text=text_intro, font=fontStyle)
label.place(relx=0.1, rely=0.1)
close_button = Button(root, text="Close", command=exitclick, height=10, width = 30)
# close_button.place(relx=0.8, rely=20)
close_button.place(relx=0.4, rely=0.8)
e = Entry(root, width=35, borderwidth=5)
app = FullScreenApp(root)
root.mainloop()