在 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()
旁白:我修正了你第一个问题的语法。
注意:
我写的一些东西对你来说可能是不必要的,直到你意识到你制作的每个应用程序都可以从下面的模板开始。只需更改 WIDTH、HEIGHT 和 TITLE 值即可为您想要构建的任何内容奠定基础。它不是“最好的”模板,但肯定不是坏的。当您变得更好时,您可以使您的模板更好,并了解为什么它会更好。
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