Hangman Game: Code inside class not working, Labels, buttons not appearing











up vote
-1
down vote

favorite












I'm working on a Tkinter GUI based hangman game in Python. In my opinion the problem is that the lines of code in the class is not reachable that's why labels and buttons are not appearing in the GUI.



I am having trouble figuring out the reason why the code in the class is not reachable.
Any sort of help will be greatly appreciated, I have to complete this project as soon as possible.



from tkinter import *
root = Tk()

#TITLE
root.title('New Application')
root.geometry("900x640+300+0")

#HEADING
heading = Label(root, text="GAME",font='bold,34',fg='black')

#ENTER GUESS LABEL
Label59=Label(root,text='Enter your guess:',font='bold,15',fg='blue')
Label59.place(x=2,y=90)

#PERSON'S GUESS
guess = StringVar()

#ENTRY BOX
entry_box = Entry(root, textvariable=guess, width=25)
entry_box.place(x=137, y=94)

#SECRET WORD THAT WE SET
secret_word=('humayun')

#TELLING LENGTH OF SECRET WORD
length=len(secret_word)
secret_word_len=Label(root,text=length, fg='black', font='bold,25,ariel')
len_tell=Label(root,text='Letters Present:',font='bold,32,ariel',fg='black')
len_tell.place(x=2,y=18)
secret_word_len.place(x=115,y=18)
hint=Label(root,text="HINT= Name",font='bold,30,ariel',fg='steelblue')
hint.place(x=2,y=50)

#CLASS
class MYGUI():
def test(self,root):
self.main_window = root

#Frames
self.top_frame = Frame(root)
self.top_frame.pack(side=TOP)
self.center_frame = Frame(root)
self.center_frame.pack(side=CENTER)
self.bottom_frame = Frame(root)
self.bottom_frame.pack(side=BOTTOM)
#Top frame labels
self.label1 = Label(root,self.top_frame, text='Hangman parts:')
self.label2 = Label(root,self.top_frame, text="")

# Center frame Labels
self.label9 = Label(root,self.center_frame, text = "")

# Bottom Frame Labels
self.label4 = Label(root,self.bottom_frame, text='guess a letter:')
self.entry1 = Entry(root,self.bottom_frame, width=5)
self.button2 = Button(root,self.bottom_frame, text='Exit', command =
self.main_window.quit())

self.life = 7
self.guess_1 = ''

for self.guess_1 in secret_word:
self.label9=Label(root,self.guess_1)
if self.guess_1 in secret_word:
print(self.guess_1)
else:
self.label9=Label(root, text="_")
self.life -= 1
if self.life is 6:
self.label1=Label(root, text='eyes')
elif self.life is 5:
self.label1=Label(root, text='head')
elif self.life is 4:
self.label1=Label(root, text='hand')
elif self.life is 3:
self.label1=Label(root, text='torso')
elif self.life is 2:
self.label1=Label(root, text='right leg')
elif self.life is 1:
self.label1=Label(root, text='left leg')

self.label1.pack(side=LEFT)
self.label2.pack(side=RIGHT)
self.label4.pack(side=LEFT)
self.label9.pack(side=TOP)
self.entry1.pack(side=LEFT)
self.button2.pack(side=LEFT)

#ENTER BUTTON
work = Button(root, text='Enter', width=15, height=1, bg='steelblue',
command=MYGUI.test)
work.place(x=300,y=90)

heading.pack()
root.mainloop()









share|improve this question







New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Your code cannot run because it is not valid python. Start by fixing your indentation.
    – Goyo
    2 hours ago

















up vote
-1
down vote

favorite












I'm working on a Tkinter GUI based hangman game in Python. In my opinion the problem is that the lines of code in the class is not reachable that's why labels and buttons are not appearing in the GUI.



I am having trouble figuring out the reason why the code in the class is not reachable.
Any sort of help will be greatly appreciated, I have to complete this project as soon as possible.



from tkinter import *
root = Tk()

#TITLE
root.title('New Application')
root.geometry("900x640+300+0")

#HEADING
heading = Label(root, text="GAME",font='bold,34',fg='black')

#ENTER GUESS LABEL
Label59=Label(root,text='Enter your guess:',font='bold,15',fg='blue')
Label59.place(x=2,y=90)

#PERSON'S GUESS
guess = StringVar()

#ENTRY BOX
entry_box = Entry(root, textvariable=guess, width=25)
entry_box.place(x=137, y=94)

#SECRET WORD THAT WE SET
secret_word=('humayun')

#TELLING LENGTH OF SECRET WORD
length=len(secret_word)
secret_word_len=Label(root,text=length, fg='black', font='bold,25,ariel')
len_tell=Label(root,text='Letters Present:',font='bold,32,ariel',fg='black')
len_tell.place(x=2,y=18)
secret_word_len.place(x=115,y=18)
hint=Label(root,text="HINT= Name",font='bold,30,ariel',fg='steelblue')
hint.place(x=2,y=50)

#CLASS
class MYGUI():
def test(self,root):
self.main_window = root

#Frames
self.top_frame = Frame(root)
self.top_frame.pack(side=TOP)
self.center_frame = Frame(root)
self.center_frame.pack(side=CENTER)
self.bottom_frame = Frame(root)
self.bottom_frame.pack(side=BOTTOM)
#Top frame labels
self.label1 = Label(root,self.top_frame, text='Hangman parts:')
self.label2 = Label(root,self.top_frame, text="")

# Center frame Labels
self.label9 = Label(root,self.center_frame, text = "")

# Bottom Frame Labels
self.label4 = Label(root,self.bottom_frame, text='guess a letter:')
self.entry1 = Entry(root,self.bottom_frame, width=5)
self.button2 = Button(root,self.bottom_frame, text='Exit', command =
self.main_window.quit())

self.life = 7
self.guess_1 = ''

for self.guess_1 in secret_word:
self.label9=Label(root,self.guess_1)
if self.guess_1 in secret_word:
print(self.guess_1)
else:
self.label9=Label(root, text="_")
self.life -= 1
if self.life is 6:
self.label1=Label(root, text='eyes')
elif self.life is 5:
self.label1=Label(root, text='head')
elif self.life is 4:
self.label1=Label(root, text='hand')
elif self.life is 3:
self.label1=Label(root, text='torso')
elif self.life is 2:
self.label1=Label(root, text='right leg')
elif self.life is 1:
self.label1=Label(root, text='left leg')

self.label1.pack(side=LEFT)
self.label2.pack(side=RIGHT)
self.label4.pack(side=LEFT)
self.label9.pack(side=TOP)
self.entry1.pack(side=LEFT)
self.button2.pack(side=LEFT)

#ENTER BUTTON
work = Button(root, text='Enter', width=15, height=1, bg='steelblue',
command=MYGUI.test)
work.place(x=300,y=90)

heading.pack()
root.mainloop()









share|improve this question







New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Your code cannot run because it is not valid python. Start by fixing your indentation.
    – Goyo
    2 hours ago















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm working on a Tkinter GUI based hangman game in Python. In my opinion the problem is that the lines of code in the class is not reachable that's why labels and buttons are not appearing in the GUI.



I am having trouble figuring out the reason why the code in the class is not reachable.
Any sort of help will be greatly appreciated, I have to complete this project as soon as possible.



from tkinter import *
root = Tk()

#TITLE
root.title('New Application')
root.geometry("900x640+300+0")

#HEADING
heading = Label(root, text="GAME",font='bold,34',fg='black')

#ENTER GUESS LABEL
Label59=Label(root,text='Enter your guess:',font='bold,15',fg='blue')
Label59.place(x=2,y=90)

#PERSON'S GUESS
guess = StringVar()

#ENTRY BOX
entry_box = Entry(root, textvariable=guess, width=25)
entry_box.place(x=137, y=94)

#SECRET WORD THAT WE SET
secret_word=('humayun')

#TELLING LENGTH OF SECRET WORD
length=len(secret_word)
secret_word_len=Label(root,text=length, fg='black', font='bold,25,ariel')
len_tell=Label(root,text='Letters Present:',font='bold,32,ariel',fg='black')
len_tell.place(x=2,y=18)
secret_word_len.place(x=115,y=18)
hint=Label(root,text="HINT= Name",font='bold,30,ariel',fg='steelblue')
hint.place(x=2,y=50)

#CLASS
class MYGUI():
def test(self,root):
self.main_window = root

#Frames
self.top_frame = Frame(root)
self.top_frame.pack(side=TOP)
self.center_frame = Frame(root)
self.center_frame.pack(side=CENTER)
self.bottom_frame = Frame(root)
self.bottom_frame.pack(side=BOTTOM)
#Top frame labels
self.label1 = Label(root,self.top_frame, text='Hangman parts:')
self.label2 = Label(root,self.top_frame, text="")

# Center frame Labels
self.label9 = Label(root,self.center_frame, text = "")

# Bottom Frame Labels
self.label4 = Label(root,self.bottom_frame, text='guess a letter:')
self.entry1 = Entry(root,self.bottom_frame, width=5)
self.button2 = Button(root,self.bottom_frame, text='Exit', command =
self.main_window.quit())

self.life = 7
self.guess_1 = ''

for self.guess_1 in secret_word:
self.label9=Label(root,self.guess_1)
if self.guess_1 in secret_word:
print(self.guess_1)
else:
self.label9=Label(root, text="_")
self.life -= 1
if self.life is 6:
self.label1=Label(root, text='eyes')
elif self.life is 5:
self.label1=Label(root, text='head')
elif self.life is 4:
self.label1=Label(root, text='hand')
elif self.life is 3:
self.label1=Label(root, text='torso')
elif self.life is 2:
self.label1=Label(root, text='right leg')
elif self.life is 1:
self.label1=Label(root, text='left leg')

self.label1.pack(side=LEFT)
self.label2.pack(side=RIGHT)
self.label4.pack(side=LEFT)
self.label9.pack(side=TOP)
self.entry1.pack(side=LEFT)
self.button2.pack(side=LEFT)

#ENTER BUTTON
work = Button(root, text='Enter', width=15, height=1, bg='steelblue',
command=MYGUI.test)
work.place(x=300,y=90)

heading.pack()
root.mainloop()









share|improve this question







New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm working on a Tkinter GUI based hangman game in Python. In my opinion the problem is that the lines of code in the class is not reachable that's why labels and buttons are not appearing in the GUI.



I am having trouble figuring out the reason why the code in the class is not reachable.
Any sort of help will be greatly appreciated, I have to complete this project as soon as possible.



from tkinter import *
root = Tk()

#TITLE
root.title('New Application')
root.geometry("900x640+300+0")

#HEADING
heading = Label(root, text="GAME",font='bold,34',fg='black')

#ENTER GUESS LABEL
Label59=Label(root,text='Enter your guess:',font='bold,15',fg='blue')
Label59.place(x=2,y=90)

#PERSON'S GUESS
guess = StringVar()

#ENTRY BOX
entry_box = Entry(root, textvariable=guess, width=25)
entry_box.place(x=137, y=94)

#SECRET WORD THAT WE SET
secret_word=('humayun')

#TELLING LENGTH OF SECRET WORD
length=len(secret_word)
secret_word_len=Label(root,text=length, fg='black', font='bold,25,ariel')
len_tell=Label(root,text='Letters Present:',font='bold,32,ariel',fg='black')
len_tell.place(x=2,y=18)
secret_word_len.place(x=115,y=18)
hint=Label(root,text="HINT= Name",font='bold,30,ariel',fg='steelblue')
hint.place(x=2,y=50)

#CLASS
class MYGUI():
def test(self,root):
self.main_window = root

#Frames
self.top_frame = Frame(root)
self.top_frame.pack(side=TOP)
self.center_frame = Frame(root)
self.center_frame.pack(side=CENTER)
self.bottom_frame = Frame(root)
self.bottom_frame.pack(side=BOTTOM)
#Top frame labels
self.label1 = Label(root,self.top_frame, text='Hangman parts:')
self.label2 = Label(root,self.top_frame, text="")

# Center frame Labels
self.label9 = Label(root,self.center_frame, text = "")

# Bottom Frame Labels
self.label4 = Label(root,self.bottom_frame, text='guess a letter:')
self.entry1 = Entry(root,self.bottom_frame, width=5)
self.button2 = Button(root,self.bottom_frame, text='Exit', command =
self.main_window.quit())

self.life = 7
self.guess_1 = ''

for self.guess_1 in secret_word:
self.label9=Label(root,self.guess_1)
if self.guess_1 in secret_word:
print(self.guess_1)
else:
self.label9=Label(root, text="_")
self.life -= 1
if self.life is 6:
self.label1=Label(root, text='eyes')
elif self.life is 5:
self.label1=Label(root, text='head')
elif self.life is 4:
self.label1=Label(root, text='hand')
elif self.life is 3:
self.label1=Label(root, text='torso')
elif self.life is 2:
self.label1=Label(root, text='right leg')
elif self.life is 1:
self.label1=Label(root, text='left leg')

self.label1.pack(side=LEFT)
self.label2.pack(side=RIGHT)
self.label4.pack(side=LEFT)
self.label9.pack(side=TOP)
self.entry1.pack(side=LEFT)
self.button2.pack(side=LEFT)

#ENTER BUTTON
work = Button(root, text='Enter', width=15, height=1, bg='steelblue',
command=MYGUI.test)
work.place(x=300,y=90)

heading.pack()
root.mainloop()






python python-3.x tkinter






share|improve this question







New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Humayun Hassan

11




11




New contributor




Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Humayun Hassan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Your code cannot run because it is not valid python. Start by fixing your indentation.
    – Goyo
    2 hours ago




















  • Your code cannot run because it is not valid python. Start by fixing your indentation.
    – Goyo
    2 hours ago


















Your code cannot run because it is not valid python. Start by fixing your indentation.
– Goyo
2 hours ago






Your code cannot run because it is not valid python. Start by fixing your indentation.
– Goyo
2 hours ago



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Humayun Hassan is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203349%2fhangman-game-code-inside-class-not-working-labels-buttons-not-appearing%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Humayun Hassan is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Humayun Hassan is a new contributor. Be nice, and check out our Code of Conduct.













Humayun Hassan is a new contributor. Be nice, and check out our Code of Conduct.












Humayun Hassan is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203349%2fhangman-game-code-inside-class-not-working-labels-buttons-not-appearing%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Landwehr

Reims

Javascript gets undefined on array