1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] GUI scale issue

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to programming and I am developing a vending machine GUI for my Raspberry Pi touchscreen display 2. I have build the GUI around the resolution of 800x400 and it looks correct on my computer however when I input the program to the pi. The GUI shrinks and does not take the wholescreen.

    I could potentially fix this but rewriting the program to suit full screen however there is will be a resolution issue due to different screen sizes.

    How can I just scale the GUI to fit the screen?

    Kindest regards, Ethan :D

    from customtkinter import *


    class app(CTk):
    def __init__(self):
    super().__init__()
    self.geometry("800x400")
    self.configure(fg_color='black')
    self.title("VendingMachine.exe")
    self.overrideredirect(True)

    self.minsize(800,400)
    self.maxsize(800,400)

    self.Success_screen = success_screen(self)
    self.Banner = banner(self)
    self.Body = body(self)
    self.button_hub = button_hub(self,self.Success_screen)
    self.Side_menu = side_menu(self)


    self.Item_overlay = item_overlay(self.Body,self.button_hub)
    self.Item_overlay2 = item_overlay2(self.Body,self.button_hub)
    self.Item_overlay3 = item_overlay3(self.Body,self.button_hub)
    self.Item_overlay4 = item_overlay4(self.Body,self.button_hub)

    self.Item = item(self.Body,self.Item_overlay,self.Item_overlay2,self.Item_overlay3,self.Item_overlay4)
    self.Item2 = item2(self.Body,self.Item_overlay2,self.Item_overlay,self.Item_overlay3,self.Item_overlay4)
    self.Item3 = item3(self.Body,self.Item_overlay3,self.Item_overlay,self.Item_overlay2,self.Item_overlay4)
    self.Item4 = item4(self.Body,self.Item_overlay4,self.Item_overlay,self.Item_overlay2,self.Item_overlay3)


    self.mainloop()


    class success_screen(CTkFrame):
    def __init__(self,parent):
    super().__init__(parent)
    self.configure(width=800,height=400,fg_color='black',corner_radius=0)
    self.place(x=0,y=0)

    CTkButton(self,text='Transaction successful',text_color='White',font=("Arial",30,"bold"),width=800,height=400,command=lambda:self.lower()).place(x=0,y=0)

    class banner(CTkFrame):
    def __init__(self,parent):
    super().__init__(parent)
    self.configure(width=800,height=25,fg_color='red',corner_radius=0)
    self.pack(side=TOP)

    class body(CTkScrollableFrame):
    def __init__(self,parent):
    super().__init__(parent)
    self.configure(width=500,height=375,fg_color='black',corner_radius=0)



    self.pack(side=LEFT,anchor='w')

    class button_hub(CTkFrame):
    def __init__(self,parent,Success_screen):
    super().__init__(parent)
    self.configure(width=284,height=50,fg_color='Yellow',corner_radius=0)
    self.place(x=516,y=350)

    self.Success_screen = Success_screen

    Cancel_btn = CTkButton(self,text='Cancel',width=150,height=50,corner_radius=0,fg_color='red',hover=False,command=lambda:(item_text_display.configure(text='Select an item'),item_cost_display.configure(text='Due: $0.00'),self.lower()))
    Cancel_btn.place(x=150,y=0)
    confirm_btn = CTkButton(self,text='Confirm',width=150,height=50,corner_radius=0,fg_color='green',hover=False,command=lambda:self.Success_screen.tkraise())
    confirm_btn.place(x=0,y=0)


    class side_menu(CTkFrame):
    def __init__(self,parent):
    super().__init__(parent)
    self.configure(width=300,height=375,fg_color='black',corner_radius=0)
    self.pack(side=RIGHT,anchor='e')
    display = CTkButton(self,text='',width=300,height=200,corner_radius=0)
    display.place(x=0,y=0)
    global item_text_display
    item_text_display = CTkLabel(self,text=f'Select an item',font=("Arial",20,"bold"),text_color='white')
    item_text_display.place(x=10,y=300)
    global item_cost_display
    item_cost_display = CTkLabel(self,text=f'Due: $0.00',font=("Arial",20,"bold"),text_color='white')
    item_cost_display.place(x=160,y=300)





    class item_overlay(CTkFrame):
    def __init__(self,parent,Buttonhub):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='red')
    self.grid(row=0,column=0,padx=20)


    self.button_hub = Buttonhub

    global item_text_display
    global item_cost_display


    return_btn = CTkButton(self,text='',fg_color='pink',width=150,height=150,corner_radius=0, hover=False,command=lambda: self.lower())
    return_btn.place(x=0,y=0)

    Add_item_btn = CTkButton(self,text='Add',fg_color='Green',width=150,height=50,corner_radius=0,hover=False,command=lambda: (item_text_display.configure(text='Item 1'),item_cost_display.configure(text="Due: $5.00"),self.lower(),self.button_hub.tkraise()))
    Add_item_btn.place(x=0,y=150)







    class item(CTkFrame):
    def __init__(self,parent,Item_overlay,Item_overlay2,Item_overlay3,Item_overlay4):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='blue')
    self.grid(row=0,column=0,padx=20)

    self.Item_overlay = Item_overlay
    self.Item_overlay2 = Item_overlay2
    self.Item_overlay3 = Item_overlay3
    self.Item_overlay4 = Item_overlay4






    screen_button = CTkButton(self,text='',corner_radius=0,width=150,height=200,command=lambda:(self.Item_overlay2.lower(),self.Item_overlay3.lower(),self.Item_overlay4.lower(),Item_overlay.tkraise()))
    screen_button.place(x=0,y=0)






    class item_overlay2(CTkFrame):
    def __init__(self,parent,Buttonhub):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='red')
    self.grid(row=0,column=1,padx=20)


    self.button_hub = Buttonhub

    global item_text_display
    global item_cost_display


    return_btn = CTkButton(self,text='',fg_color='purple',width=150,height=150,corner_radius=0, hover=False,command=lambda: self.lower())
    return_btn.place(x=0,y=0)

    Add_item_btn = CTkButton(self,text='Add',fg_color='Green',width=150,height=50,corner_radius=0,hover=False,command=lambda: (item_text_display.configure(text='Item 2'),item_cost_display.configure(text="Due: $6.00"),self.lower(),self.button_hub.tkraise()))
    Add_item_btn.place(x=0,y=150)


    class item2(CTkFrame):
    def __init__(self,parent,Item_overlay2,Item_overlay,Item_overlay3,Item_overlay4):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='blue')
    self.grid(row=0,column=1,padx=60)


    self.Item_overlay2 = Item_overlay2
    self.Item_overlay = Item_overlay
    self.Item_overlay3 = Item_overlay3
    self.Item_overlay4 = Item_overlay4




    screen_button = CTkButton(self,text='',corner_radius=0,width=150,height=200, command=lambda:(self.Item_overlay.lower(),self.Item_overlay3.lower(),self.Item_overlay4.lower(),Item_overlay2.tkraise()))
    screen_button.place(x=0,y=0)


    class item_overlay3(CTkFrame):
    def __init__(self,parent,Buttonhub):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='red')
    self.grid(row=1,column=0,padx=20)


    self.button_hub = Buttonhub

    global item_text_display
    global item_cost_display


    return_btn = CTkButton(self,text='',fg_color='red',width=150,height=150,corner_radius=0, hover=False,command=lambda: self.lower())
    return_btn.place(x=0,y=0)

    Add_item_btn = CTkButton(self,text='Add',fg_color='Green',width=150,height=50,corner_radius=0,hover=False,command=lambda: (item_text_display.configure(text='Item 3'),item_cost_display.configure(text="Due: $6.00"),self.lower(),self.button_hub.tkraise()))
    Add_item_btn.place(x=0,y=150)



    class item3(CTkFrame):
    def __init__(self,parent,Item_overlay3,Item_overlay,Item_overlay2,Item_overlay4):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='blue')
    self.grid(row=1,column=0,padx=20, pady=20)
    self.Item_overlay3 = Item_overlay3
    self.Item_overlay = Item_overlay
    self.Item_overlay2 = Item_overlay2
    self.Item_overlay4 = Item_overlay4






    screen_button = CTkButton(self,text='',corner_radius=0,width=150,height=200, command=lambda:(self.Item_overlay.lower(),self.Item_overlay2.lower(),self.Item_overlay4.lower(),Item_overlay3.tkraise()))
    screen_button.place(x=0,y=0)



    class item_overlay4(CTkFrame):
    def __init__(self,parent,Buttonhub):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='red')
    self.grid(row=1,column=1,padx=20)


    self.button_hub = Buttonhub

    global item_text_display
    global item_cost_display


    return_btn = CTkButton(self,text='',fg_color='red',width=150,height=150,corner_radius=0, hover=False,command=lambda: self.lower())
    return_btn.place(x=0,y=0)

    Add_item_btn = CTkButton(self,text='Add',fg_color='Green',width=150,height=50,corner_radius=0,hover=False,command=lambda: (item_text_display.configure(text='Item 4'),item_cost_display.configure(text="Due: $6.00"),self.lower(),self.button_hub.tkraise()))
    Add_item_btn.place(x=0,y=150)



    class item4(CTkFrame):
    def __init__(self,parent,Item_overlay4,Item_overlay,Item_overlay2,Item_overlay3):
    super().__init__(parent)

    self.configure(width=150,height=200,corner_radius=0,fg_color='blue')
    self.grid(row=1,column=1,padx=60, pady=20)

    self.Item_overlay4 = Item_overlay4
    self.Item_overlay1 = Item_overlay
    self.Item_overlay2 = Item_overlay2
    self.Item_overlay3 = Item_overlay3





    screen_button = CTkButton(self,text='',corner_radius=0,width=150,height=200, command=lambda:(self.Item_overlay1.lower(),self.Item_overlay2.lower(),self.Item_overlay3.lower(),Item_overlay4.tkraise()))
    screen_button.place(x=0,y=0)





    app()

    Continue reading...

Compartilhe esta Página