I've been struggling for days trying to figure out the problem in my file. So now I've stripped the whole file down to a minimum with only the problems.
After I added the counting fuction, the problems appeared.
I've been trying several different ways to fix this one without luck. Searched this site up and down and still can't find any answer or questions thats similar to this one with multiple errors.
- EDIT:
- The code can now be directly imported. The old import didtnt work as planned.
- 1st: The problem is that I don't want root to open two windows. But without calling "root=Tk", the "tk.StringVar" will not work.
- 2nd: The counter only shows the number in console. I want it to show in "l = Label(f3, textvariable=click) # Score"
- 3rd: What is the root if tk() is allready a "root" without calling root=tk()? And why do I get the error "AttributeError: 'NoneType' object has no attribute '_root'" when I'm not calling root anything?
- I'm not that into Python and Tk yet. So I can't figure out a clever answer myself.
Might be a minder issue for someone with more experience in Python and Tk then me.
Would be extremely glad for any help.
EDIT 2:
UPDATE! Found the problem myself after days of struggling.
Needed to add "self." before "click". Removed "root=tk()", removed "from tkinter import*" and added "tk." for every button, checkbutton, labels and frames and now it finally works. The code is now updated aswell.
import tkinter as tk
Large_font= ("arial", 30)
class Myapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Payment")
#root.withdraw()
self.geometry("1280x1024")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (Homepage, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(Homepage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class Homepage(tk.Frame):
def __init__(self, parent, controller, **kwargs):
Frame.__init__(self, parent, **kwargs)
self.configure(background='grey')
f1 = tk.Frame(self, width=1200, height=100, bd=3, bg="grey", relief="raise")
f1.pack(side="top")
lblInfo = tk.Label(f1, text="MY APP", font=Large_font, bg="grey", fg="white")
lblInfo.pack(side="top")
#=========SUM UP==========
f3 = tk.Frame(self, width=400, height=800, bd=3, bg="grey", relief="raise")
f3.pack(side="right")
def uiPrint():
print("")
print(clickcount)
blankLine()
self.click = tk.IntVar()
self.click.set("6");
def blankLine():
for i in range(0):
print("")
def buttonCommand():
global clickcount
global click
global mult
clickcount += 2 * (mult)
self.click.set(str(clickcount)); # Update score
uiPrint()
def buttonCommand1():
global clickcount
global click
global mult
clickcount -= 1 * (mult)
self.click.set(str(clickcount));
uiPrint()
l = tk.Label(f3, textvariable=click) # Score
l.pack()
plusButton = tk.Button(f3, command = buttonCommand, text="+")
minusButton = tk.Button(f3, command = buttonCommand1, text="-")
plusButton.pack(padx=10, pady=10)
minusButton.pack(padx=10, pady=10)
btn1 = tk.Button(f3, padx=20, pady=20, bd=8, fg="white", bg="green", font=('arial', 30, 'bold'),
text="NEXT")
btn1.pack(padx=10, pady=10)
clickcount = (6)
mult = 1
dcp1 = 0
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.configure(background='grey')
f1 = tk.Frame(self, width=600, height=100, bd=3, bg="grey", relief="raise")
f1.pack()
app = Myapp()
app.mainloop()