0

I am following a little frame tutorial for tkinter. I want to know how to change the size of the screen. At the moment, the screen size changes, but when I change the background colour, it does not affect the whole screen.

from tkinter import *
import tkinter

class sign_in(tkinter.Tk):

    def __init__(self):
        tkinter.Tk.__init__(self)
        container = tkinter.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        self.title("Snake Login")
        self.geometry("250x300")

        self.resizable(False, False)


        self.frames = {}
        for F in (StartPage, PageOne, PageTwo):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage")

    def show_frame(self, page_name):
        frame = self.frames[page_name]
        frame.tkraise()


class StartPage(tkinter.Frame):

    def __init__(self, parent, controller):
        tkinter.Frame.__init__(self, parent)

        self.controller = controller
        self.configure(background="#1affff")
        label = tkinter.Label(self, text="This is the start page")
        label.place(x=10,y=10)

        button1 = tkinter.Button(self, text="Go to Page One",
                            command=lambda: controller.show_frame("PageOne"))
        button2 = tkinter.Button(self, text="Go to Page Two",
                            command=lambda: controller.show_frame("PageTwo"))
        button1.pack()
        button2.pack()

class PageOne(tkinter.Frame):

    def __init__(self, parent, controller):
        tkinter.Frame.__init__(self, parent)
        self.controller = controller
        label = tkinter.Label(self, text="This is page 1")
        label.place(x=100,y=100)
        button = tkinter.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("StartPage"))
        button.place(x=50,y=30)


class PageTwo(tkinter.Frame):

    def __init__(self, parent, controller):
        tkinter.Frame.__init__(self, parent)
        self.controller = controller
        label = tkinter.Label(self, text="This is page 2")
        label.pack(side="top", fill="x", pady=10)
        button = tkinter.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("StartPage"))
        button.pack()


if __name__ == "__main__":
    sign_in().mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
  • What exactly is it that you want to know? Resizing or changing background color? – martineau Sep 20 '19 at 19:31
  • @martineau i am trying to resize the whole screen. at the moment, when i do self.geometry("250x300"), it changes the screen size but nothing is shown in the space. you can only see it in the top left corner. i want it so that the whole screen is visible – KhalaMan2000 Sep 20 '19 at 19:33
  • I think doing what you want using the technique being used would be a problem because using `frame.tkraise()` to move the desired frame above all the others so it's visible assumes they're the same size — otherwise a bigger, but lower down one wouldn't be completely covered up by the top-most one. – martineau Sep 20 '19 at 19:45
  • @martineau so how would i be able to make use of the whole screen, and not just the corner – KhalaMan2000 Sep 20 '19 at 19:48
  • You would have to place the widgets so they weren't all in the corner. tkinter has several different geometry or [layout managers](http://web.archive.org/web/20190225104038id_/http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/layout-mgt.html) — named `grid`, `place`, and `pack` — so the details would depend on which one was being used. Each Frame can use a different one, in fact. I think most a documented (to some degree) in the [tkinterbook](http://effbot.org/tkinterbook/). – martineau Sep 20 '19 at 20:13
  • Also see [Display fullscreen mode on Tkinter](https://stackoverflow.com/questions/7966119/display-fullscreen-mode-on-tkinter). It also show how to determine the screen's width and height. – martineau Sep 20 '19 at 20:15
  • @martineau thats the thing, even if i place the widgets in a different place, it doesnt show. it will only show in the top left. Try running the code so you can get a visual idea. idk how to show pictures on this website :P – KhalaMan2000 Sep 20 '19 at 20:16
  • @KhalaMan2000: Add `container.grid_rowconfigure(0, weight=1)` and `container.grid_columnconfigure(0, weight=1)` read [Tkinter.Grid.grid_rowconfigure-method](http://effbot.org/tkinterbook/grid.htm#Tkinter.Grid.grid_rowconfigure-method) – stovfl Sep 20 '19 at 20:44
  • 1
    That's not a very good starting point for learning tkinter. You should probably start with a more basic tutorial. – Bryan Oakley Sep 20 '19 at 21:10

0 Answers0