python - python结构约定tkinter
问题描述
我不确定如何构建我的 python 代码以遵循编程约定,我的老师告诉我从一开始就启动测验 GUI 对象而不是主,但我不确定她的意思。这是我的代码的基本版本:
# Import everything from Tkinter module
from tkinter import *
def function():
blajslaksjd
def another_function():
blahblah
# quiz is the tkinter box
# I am going to change the positions to the help menu bar
quiz = Tk()
quiz.geometry('800x800-100+20')
# Menu bar
menu_bar = Menu(quiz)
quiz.config(menu=menu_bar)
help_menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Help", menu=help_menu)
# Global variables
variable = 0
# Another variable
question = 0
# Displays the actual question
question_label = Label(text="insert question", font="bold, 13")
# Radio buttons for some functons
option_1 = Radiobutton(quiz, text="text", value=1)
option_2 = Radiobutton(quiz, text="text", value=2)
option_3 = Radiobutton(quiz, text="text", value=3)
option_4 = Radiobutton(quiz, text="text", value=4)
# Label for function
blah = Label(text="Blah")
# Button for function
blahh = Button(quiz, text="BLAHH")
# Display tkinter box
quiz.mainloop()
如果我把它改成这样会更好吗?我将帮助定义 tkinter 框的属性的代码移到顶部。
# Import everything from Tkinter module
from tkinter import *
# quiz is the tkinter box
quiz = Tk()
quiz.geometry('800x800-100+20')
# Menu bar
menu_bar = Menu(quiz)
quiz.config(menu=menu_bar)
help_menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Help", menu=help_menu)
def function():
blajslaksjd
def another_function():
blahblah
# Global variables
variable = 0
# Another variable
question = 0
# Displays the actual question
question_label = Label(text="insert question", font="bold, 13")
# Radio buttons for some functons
option_1 = Radiobutton(quiz, text="text", value=1)
option_2 = Radiobutton(quiz, text="text", value=2)
option_3 = Radiobutton(quiz, text="text", value=3)
option_4 = Radiobutton(quiz, text="text", value=4)
# Label for function
blah = Label(text="Blah")
# Button for function
blahh = Button(quiz, text="BLAHH")
# Display tkinter box
quiz.mainloop()
或这个?我将帮助定义 tkinter 框属性的代码移到了底部。
# Import everything from Tkinter module
from tkinter import *
def function():
blajslaksjd
def another_function():
blahblah
# Global variables
variable = 0
# Another variable
question = 0
# Displays the actual question
question_label = Label(text="insert question", font="bold, 13")
# Radio buttons for some functons
option_1 = Radiobutton(quiz, text="text", value=1)
option_2 = Radiobutton(quiz, text="text", value=2)
option_3 = Radiobutton(quiz, text="text", value=3)
option_4 = Radiobutton(quiz, text="text", value=4)
# Label for function
blah = Label(text="Blah")
# Button for function
blahh = Button(quiz, text="BLAHH")
# quiz is the tkinter box
quiz = Tk()
quiz.geometry('800x800-100+20')
# Menu bar
menu_bar = Menu(quiz)
quiz.config(menu=menu_bar)
help_menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Help", menu=help_menu)
# Display tkinter box
quiz.mainloop()
解决方案
推荐阅读
- visual-c++ - VC++ 2017:尝试使用 RC 编译 .rc 文件时出错
- mysql - 使用resultmap时如何计算?
- jmeter - 如何在现有的 Jmeter 脚本中设置 CBLite
- reactjs - 当状态中只有一个字段发生变化时,如何避免重新渲染所有 React 纯组件?
- phpexcel - 如何在 PHPExcel 中获取特定行的列数?
- python - 两列唯一字符串
- javascript - 带有 vue-router 的谷歌收件箱式导航
- python - 为什么在 Keras 中使用多处理时推理时间会变慢?
- navision - 试图在 xml 中的特定元素名称中查找和存储特定数据?
- python - 我有一个元素列表,我想删除特定的重复元素并将其附加到 Python 3.7.2 中现有列表的开头