Reputation: 11
I am doing a bit of basic Tkinter code, and when I launch I get no errors, but my window is empty, even though I have added things to them. I saw this question here, but that does not help me, as I have what it says to do.
from tkinter import *
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack
self.sg = Button(frame, text = "Study Guide", command = self.studyGuide)
self.sg.grid(row = 2, column = 1)
self.sg.pack()
self.quizlet = Button(frame, text = "Quizlet", command = self.quizlet)
self.quizlet.grid(row = 2, column = 2)
self.quizlet.pack()
self.flashcard = Button(frame, text = "Flash Cards", command = self.flashcard)
self.flashcard.grid(row = 2, column = 3)
self.flashcard.pack()
self.quitButton = Button(frame, text = "Quit", command = frame.quit)
self.quitButton.grid(row = 3, column = 2)
self.quitButton.pack()
self.text = Label(frame, text = "Social Studies Study Tool")
self.text.grid(row = 1, column = 2)
self.text.pack()
def studyGuide(self):
print("Study Guide")
def quizlet(self):
print("Quizlet")
def flashcard(self):
print("Flashcards")
root = Tk()
app = App(root)
root.mainloop()
Upvotes: 1
Views: 688
Reputation: 82939
Don't mix up layout managers! Use either pack()
or grid()
, but not both.
If you use pack
, add the side
where to pack the items:
frame.pack() # note the missing () in your code
...
self.sg.pack(side=TOP)
If you use grid()
, add frame.grid()
to the top of your code:
frame.grid()
...
self.sg.grid(row = 2, column = 1)
Upvotes: 1
Reputation: 76254
First, for every element that you call grid
for, don't call pack
. You only need to use one or the other. Second:
frame = Frame(master)
frame.pack
You appear to be missing a parentheses here.
frame = Frame(master)
frame.pack()
Upvotes: 2