大家好,我在项目中添加背景后遇到了问题,我什么都看不到,但调整大小后我看到了背景:我不想在对象中使用ttk
这是我的代码:
from tkinter import (Button, Label, Frame)
class HomeFrame(Frame): # Inherit Frame class
"""Application main interface"""
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.root = parent # Define internal variable root
self.root.configure(background='green')
self.home_page()
def home_page(self):
"""Load control"""
Label(self, text="First name").grid(row=0, column=0, padx=20, pady=20)
Full_name = Button(self, text="Get Full name")
Full_name.grid(row=0, column=1, columnspan=2, padx=20, pady=20)
Label(self, text="Last name").grid(row=1, column=0, padx=20, pady=20)
hello = Button(self, text="hello")
hello.grid(row=3, column=2, columnspan=2, padx=20, pady=20)
这是结果:
不调整大小的接口
调整大小后:
调整大小后的接口
from tkinter import (Button, Label, Frame)
class HomeFrame(Frame): # Inherit Frame class
"""Application main interface"""
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.root = parent # Define internal variable root
self.root.configure(background='green')
self.config(background='green')
self.home_page()
def home_page(self):
"""Load control"""
Label(self, text="First name").grid(row=0, column=0, padx=20, pady=20)
Full_name = Button(self, text="Get Full name")
Full_name.grid(row=0, column=1, columnspan=2, padx=20, pady=20)
Label(self, text="Last name").grid(row=1, column=0, padx=20, pady=20)
hello = Button(self, text="hello")
hello.grid(row=3, column=2, columnspan=2, padx=20, pady=20)