0

I am unsure how to structure my python code to follow programming conventions, my teacher told me to start the quiz GUI object at the start instead of with the main, but I am unsure what she means. This is a basic version of my code:

# 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()

Is it better if I change it to this? I moved the code which helped define the tkinter box's properties to the top.

# 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()

or this? I moved the code which helped define the tkinter box's properties to the bottom.

# 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()
Laurel Ted
  • 61
  • 9
  • Possible duplicate of [Best way to structure a tkinter application](https://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application) – Reblochon Masque Jun 19 '18 at 08:10
  • You could start with not using `*` imports: prefer `import tkinter as tk` instead. – Reblochon Masque Jun 19 '18 at 08:11
  • When you define a function name and are planning to implement it later you usually code the body as `pass`, not `blajslaksjd`. Then you'll be able to run without errors and be able to call it even if it does nothing. – figbeam Jun 19 '18 at 12:50

0 Answers0