Reputation: 29
Please be patient with me, I am 16 years old, only started programming about last year september on codeacademy. Anyway, I'm creating this program so I can get an end of term grade for math originally but now I have been told that the school may want to use it. Now I have to make the GUI pretty and whatnot and doing so I came across a problem, grid doesn't work with ".pack()" widgets in the same window such as my "root" so my question is:
How do I move things like a would with grid and place them where I want without such a limiting scope of "LEFT,RIGHT,BOTTOM,TOP"
Here is the code:
from tkinter import *
import tkinter.messagebox
import os
from tkinter import font
from tkinter import ttk
root = Tk()
root.geometry("800x500")
root.configure(background="grey")
root.title("Mathematical Assistance Program")
#********Functions**********#
def About():
Beep = tkinter.messagebox.askquestion("About", "M.A.P was created by Mykel Mills using his amazing programming skills for math is he awesome or what?")
if Beep == "yes":
tkinter.messagebox.showinfo("Thanks", "Thank you very much!")
else:
os.startfile("killthem.flv")
def Author():
AuthorWindow = Toplevel()
AuthorWindow.geometry("500x200")
AuthorWindow.title("The Developer")
photo = PhotoImage(file="pain.gif")
Label1 = Label(AuthorWindow, image=photo)
Label1.image = photo
Label1.grid(row=0, column=0)
def AddingMatrices():
os.startfile("MAdd.mp4")
tkinter.messagebox.showinfo("Here", "I've opened a PDF for you for questions.")
os.startfile("1.pdf")
def MultiplyMatrices():
os.startfile("MM1.mp4")
tkinter.messagebox.showinfo("Part 2", "Let's begin part 2!")
os.startfile("MM2.mp4")
tkinter.messagebox.showinfo("Worksheet", "I'll open a worksheet for you!")
os.startfile("MM.pdf")
#*******Menu and Sub Menu**********#
menu = Menu(root)
root.config(menu=menu)
subMenu = Menu(menu)
CSsubMenu = Menu(menu)
MatrixSubMenu = Menu(menu)
menu.add_cascade(label="Home", menu=subMenu)
menu.add_cascade(label="Choose Topic", menu=CSsubMenu)
subMenu.add_command(label="About", command=About)
subMenu.add_command(label="Developer", command=Author)
subMenu.add_separator()
subMenu.add_command(label="Help", command=root.quit)
subMenu.add_command(label="Quit", command=root.quit)
MatrixSubMenu.add_command(label="Adding and Subtracting Matrices", command=AddingMatrices)
MatrixSubMenu.add_command(label="Multiplying Matrices", command=MultiplyMatrices)
CSsubMenu.add_cascade(label="Matrices", menu=MatrixSubMenu)
CSsubMenu.add_command(label="Vectors", command=root.quit)
CSsubMenu.add_command(label="Circle Theorom", command=root.quit)
CSsubMenu.add_command(label="Algebra", command=root.quit)
#*********Status Bar**********#
status = Label(root, text="Welcome to M.A.P, I will be your host today, My name is Bob, Please request for my help by clicking the help button", bd=1, relief=SUNKEN, anchor=W)
status.pack(side=BOTTOM, fill=X)
#**********To do list******************
lf = LabelFrame(root, text="To Do", padx=5, pady=5, bg="grey")
lf.pack(side=LEFT)
label = Label(lf, text="1. Add Vector videos and questions", bg="grey")
label1 = Label(lf, text="2. Complete all other possible topics", bg="grey")
label2 = Label(lf, text="3. Create UI to be more User Friendly", bg="grey")
label3 = Label(lf, text="4. Create point system with rewards", bg="grey")
label4 = Label(lf, text="5. Design I.EM.S as soon as possible ", bg="grey")
label.pack()
label1.pack()
label2.pack()
label3.pack()
label4.pack()
#*******Home Page Title*********
label5 = Label(root, text="M.A.P", font=("Helvetica", 50), bg="grey")
label5.pack(side=TOP)
root.mainloop()
Thanks a million!
Upvotes: 0
Views: 363
Reputation: 189
Use .place()
In absolute positioning, the programmer specifies the position and the size of each widget in pixels. The size and the position of a widget do not change if you resize a window.
.place() uses x and y coordinates to specify the placement on the window.
Example:
Label.place(x=40, y=50)
Here's the URL for a full explanation of .pack() , .grid() and .place(): http://zetcode.com/gui/tkinter/layout/
Please note: .grid() is a much better and more organized way to make a Tkinter window. It is NOT as limited as you think, if you use the STICKY argument (Which allows you to be even more specific than just a single cell). I won't go too far into grid, since it isn't part of the question. But I would rather you use .grid() than .place()
Upvotes: 1