【问题标题】:How do I change specific parts of tkinter backround app?如何更改 tkinter 后台应用程序的特定部分?
【发布时间】:2020-11-28 23:27:17
【问题描述】:

我想改变我的应用程序的背景颜色,我现在的方式是这样的:

我希望我的应用看起来也像这样:

你可以看到它有一些不同的颜色,例如在顶部整个区域看起来有点灰,我想看看它是如何完成的, 这是我的代码:

root.title("Arizon")
root.geometry("620x400+0+0")
root.configure(bg='#1c1b1c')
heading = Label(root, text="Arizon Updater", font=("arial", 40, "bold"), fg="#030208", bg= "#1c1b1c").pack()
label1 = Label(root, text="Enter how much minimum value do u want to gain: ", font=("arial", 9, "bold"), fg="#f0f0f5", bg="#141314").place(x=5, y=90)

【问题讨论】:

  • heading 使用与root 相同的背景颜色。尝试将根颜色更改为#131413
  • 您不能在同一个框架中使用两个不同的几何管理器!几何经理也返回None
  • @Reblochon Masque - 您可以将placegridpack 一起使用。 packgrid 不能一起使用。
  • 那么有没有具体的做法呢?
  • 我现在迷路了

标签: python tkinter colors background-color


【解决方案1】:

在 cmets 中解释。

import tkinter as tk


class App(tk.Tk):
    #width, height and title are constants of your app so, write them as such
    WIDTH  = 620
    HEIGHT = 400
    TITLE  = 'Arizon'

    def __init__(self):
        tk.Tk.__init__(self)
        #set the app bg color
        self.configure(bg="gray2")

        #set the header bg color to something different than the app bg color
        header = tk.Label(self, text="Arizon Updater", font="arial 40 bold", fg="gray70", bg="gray18")

        #tell the header to be at the top and to fill it left to right
        header.pack(anchor='nw', fill="x")

        #name things what they are, this is a label, but more importantly it is your first question
        question_1 = tk.Label(self, text="Enter the minimum amount you want to gain: ", font="arial 9 bold", fg="gray70", bg='gray2')
        question_1.place(x=5, y=90)


#use proper PEP8 to initialize your program
if __name__ == "__main__":
    app = App()
    app.geometry(f'{App.WIDTH}x{App.HEIGHT}')
    app.title(App.TITLE)
    app.mainloop()

旁白:我修正了你第一个问题的语法。


注意:

我写的一些东西对你来说可能是不必要的,直到你意识到你制作的每个应用程序都可以从下面的模板开始。只需更改 WIDTHHEIGHTTITLE 值即可为您想要构建的任何内容奠定基础。它不是“最好的”模板,但肯定不是坏的。当您变得更好时,您可以使您的模板更好,并了解为什么它会更好。

import tkinter as tk

class App(tk.Tk):
    WIDTH  = 620
    HEIGHT = 400
    TITLE  = 'Arizon'

    def __init__(self):
        tk.Tk.__init__(self)


if __name__ == "__main__":
    app = App()
    app.geometry(f'{App.WIDTH}x{App.HEIGHT}')
    app.title(App.TITLE)
    app.mainloop()

我强烈建议您花一些时间阅读文档。如果你不这样做,你就会不断地挣扎和失败。即使你的成功也只不过是一个巨大的复制/粘贴混乱。文档是您构建所有知识的基础。我已经编程了 25 年,并且熟练地使用了大约 20 多种语言进行编程。我的 StackOverflow 问题为零。我绝对知道我在说什么。像研究圣经一样研究文档。

“Tk 允许有Frames。有Frames,它是self.good ~ The Book Of Docs 1.013rc

:D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2011-06-17
    • 2016-03-16
    相关资源
    最近更新 更多