我正在关注tkinter的一些框架教程。我想知道如何更改屏幕尺寸。目前,屏幕尺寸会发生变化,但是当我更改背景颜色时,它不会影响整个屏幕。
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()