GUI背景问题



我的问题是,我想用tkinter python创建一个GUI,并编写了这段代码,还指定了它的背景,但不知道为什么背景是完全黑色的,由于这很多东西是不可见的。输入图片描述

代码-

#we are using tkinter li
import tkinter as tk
from tkinter import *
from tkinter import messagebox
root = tk.Tk()
#we are using title command
root.title('PythonGuides')
#here we are changing its background
root.configure(background='lightgrey')
#here we are changing its
root.geometry('500x300')
root.configure(background='black')
L1 = Label(root,text="Enter name")
L1.grid(row=1,column=1,padx=5,pady=5)
E1 = Entry(root,width=30)
E1.grid(row=1 ,column=3,padx=5,pady=5)
L1 = Label(root,text="Enter Email")
L1.grid(row=2,column=1,padx=5,pady=5)
E1 = Entry(root,width=30)
E1.grid(row=2 ,column=3,padx=5,pady=5)
L1 = Label(root,text="Enter Password")
L1.grid(row=3,column=1,padx=5,pady=5)
E1 = Entry(root,width=30,show="*")
E1.grid(row=3 ,column=3,padx=5,pady=5)
L2 = Label(root,text="Select Gender")
L2.grid(row=4,column=1,padx=5,pady=5)
Cas = IntVar()
R1 = Radiobutton(root,text="Male",value=1,variable=Cas)
R2 = Radiobutton(root,text="FeMale",value=2,variable=Cas)
R3 = Radiobutton(root,text="Others",value=3,variable=Cas)
R1.grid(row=4,column=3,padx=5,pady=5)
R2.grid(row=5,column=3,padx=5,pady=5)
R3.grid(row=6,column=3,padx=5,pady=5)
C1 = Checkbutton(root,text="Verify terms and conditions")
C1.grid(row=7,column=3,padx=5,pady=5)
B1 = Button(root,width=20,padx=2,pady=2,text="Submit")
B1.grid(row=8,column=3,padx=5,pady=5)
root.mainloop()
L1 = Label(root,text="Enter name", bg="black")

为小部件添加'bg'属性。

删除第8行root.configure(background='black')

最新更新