我正在尝试Tkinter并使用网格编写一个小窗口。
代码如下:
from Tkinter import *
from modules.logic import game
import options
class StartWindow:
def __init__(self):
data = open("myData", "w")
data.close()
self.master = Tk()
self.l0 =Label (self.master, text = "W=jump", bg = "magenta", font = ("comic sans ms", 20, "bold")).grid(row=0, sticky = W)
self.l1=Label (self.master, text = "A=left",bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row = 1, sticky = W)
self.l2=Label(self.master, text = "D=Duck", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=2, sticky = W )
self.l3=Label(self.master, text = "Mouse = Shoot", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=3, sticky = W)
self.l4=Label(self.master, text = "S=Duck", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=4, sticky = W)
self.l5=Label(self.master, text="Seed:", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=5, sticky = W)
self.master.minsize(50, 50)
self.master.weight = 2
self.master.title("Fluffocalypse")
self.master.iconify()
self.e1 = Entry(self.master)
self.e1.grid(row=5, column=1, sticky = W)
self.b1 =Button(self.master, text = "Start", command = self.startGameNormally).grid(row = 6, sticky = W)
self.b2 = Button(self.master, text = "alten Spielstand laden", command =self.loadOldGame).grid(row = 7, sticky = W)
mainloop()
确实有效。
嗯,首先,文字看起来不像我的漫画,但这是一个小问题。
如果您尝试使用此代码(请执行此操作),您会看到所获得的是一个带有标签和按钮的窗口,就在我放置它们的位置时,我也将它设置为洋红色。
但是,窗口上的可用空间仍为灰色。 我想也有洋红色的自由空间。 这是可能的,如果可能的话怎么样? 关于如何更改任何打包的颜色有十几个解释,但我没有使用pack()而是网格,我无法找到关于整个窗口颜色的解决方案,而不仅仅是我的标签和按钮是。
答案 0 :(得分:5)
我想您希望窗口的背景颜色为magenta
:
self.master = Tk()
self.master.configure(bg = 'magenta')
结果:
答案 1 :(得分:2)
只需将此行添加到构造函数中:
self.master.configure(background="magenta")