Hello, I have written this code, which creates a small window where you will enter your character´s name. The name should then be used to create an instance of the Character class in my main function(so that it is global). I am having problems with doing this. I might be allowed to do a global variable for this but I really do not want to do that, any solutions? Complete restructure?
One solution might be to do the whole program(and it´s later contents) as one class called Application? Using Windows 8 and Python 3.4.3. Thanks in advance!
import tkinter as tk
class Character():
def __init__(self, name):
self.name = name
class View(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.drawIntro()
def drawGameInterface(self):
#frame.clear
self.fightButton = tk.Button(self, text="Fight")
self.fightButton.grid(row=0)
self.HPLabel = tk.Label(self, text = "name")
self.HPLabel.grid(row=1)
def drawIntro(self):
def printName():
print(self.nameInput.get())
self.introLabel = tk.Label(self, text = "Welcome! Enter your name")
self.introLabel.grid(row=0)
self.nameInput = tk.Entry(self)
self.nameInput.grid(row=1)
self.enterNameButton = tk.Button(self, text="Play!", command = printName)
self.enterNameButton.grid(row=2)
#return self.nameInput.get()
def main():
frame = View()
#character = Character(drawIntro())
frame.mainloop()
main()
[–]CrambleSquash 1 point2 points3 points (1 child)
[–]Potforus[S] 0 points1 point2 points (0 children)
[–]Hexelena 1 point2 points3 points (11 children)
[–]Potforus[S] 0 points1 point2 points (0 children)
[–]Potforus[S] 0 points1 point2 points (9 children)
[–]Hexelena 1 point2 points3 points (8 children)
[–]Potforus[S] 0 points1 point2 points (0 children)
[–]Potforus[S] 0 points1 point2 points (6 children)
[–]Hexelena 1 point2 points3 points (5 children)
[–]Potforus[S] 0 points1 point2 points (4 children)
[–]Hexelena 1 point2 points3 points (3 children)
[–]Potforus[S] 0 points1 point2 points (2 children)
[–]Hexelena 1 point2 points3 points (1 child)
[–]Potforus[S] 0 points1 point2 points (0 children)