python tkinter 框架小部件背景颜色未显示

问题描述 投票:0回答:0

我已经分享了我所有的代码片段。但是我觉得没必要/所以我只好删除大部分不相关的部分

我创建了 tkinter GUI。该功能运行良好,但问题是您会发现框架小部件的背景色不显示。

我想知道为什么?

我猜是因为我没有写frame widget的width和height。

from tkinter import *
import pandas as pd


# Create object
root = Tk()

# Adjust size
root.geometry( "600x200" )

#create frames
frame1=Frame(root,bg='white')
frame1.grid(row=0,column=0)

frame1_2=Frame(root,bg='red')
frame1_2.grid(row=1,column=0)

frame1_3=Frame(root,bg='yellow')
frame1_3.grid(row=2,column=0)

frame2=Frame(root,bg='blue')
frame2.grid(row=0,column=1)

# Dropdown menu options
options = ls_categories
options2 = ls_country

# datatype of menu text
clicked = StringVar()
clickedCountry = StringVar()

# initial menu text
clicked.set( " None " )
clickedCountry.set( " None " )

# Create Dropdown menu
drop = OptionMenu( frame1 , clicked , *options )
drop.grid(row=0,column=0)
dropCountry = OptionMenu( frame1 , clickedCountry , *options2 )
dropCountry.grid(row=0,column=2)

# Create button, it will change label text
button = Button( frame1 ,width=13, text = "select" , command = show,padx=3,pady=3 ).grid(row=2,column=0)
btnChCat = Button( frame1 ,width=13, text = "choose Category" , command = choose,padx=3,pady=3 ).grid(row=1,column=0)
btnChCountry = Button( frame1 ,width=13, text = "choose Country" , command = chooseCountry,padx=3,pady=3  ).grid(row=1,column=2)
bntSubmit=Button(frame1_2,width=13,text="Search", command=f_submit,padx=3,pady=3 ).grid(row=0,column=0)
bntLinks=Button(frame1_3,width=13,text="GetWebLinks", command=a_links,padx=3,pady=3 ).grid(row=0,column=0)

# Create Label
label = Label( frame1 , text = " " )
label.grid(row=1,column=1)
label2 = Label( frame2 , text = " " )
label2.grid(row=4,column=0)

# Execute tkinter
root.mainloop()
python tkinter background frame
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.