更新** TK / ROOT / Not CALLABLE,多个问题,AttributeError:'NoneType'对象没有属性'_root'

时间:2018-03-07 18:15:48

标签: python-3.x tkinter root callable

我一直在努力解决我档案中的问题。 所以现在我已经将整个文件删除到最低限度,只有问题。

添加计数功能后,出现了问题。

我一直在尝试几种不同的方法来解决这个问题而没有运气。 上下搜索此网站仍然找不到任何类似于这个有多个错误的答案或问题。

  • 编辑:
  • 现在可以直接导入代码。旧的进口没有按计划运作。
  • 1st:问题是我不希望root打开两个窗口。但是如果不调用“root = Tk”,“tk.StringVar”将无效。
  • 第二:计数器仅显示控制台中的数字。我希望它以“l =标签(f3,textvariable = click)#Score”
  • 显示
  • 3rd:如果tk()已经是“root”而没有调用root = tk(),那么root是什么? 为什么我得到错误“AttributeError:'NoneType'对象没有属性'_root'”当我没有调用root时呢?

- 我还没有进入Python和Tk。所以我自己无法找出一个聪明的答案。

对于那些在Python和Tk方面有更多经验的人来说,这可能是个问题。

对任何帮助都会非常高兴。

编辑2:

UPDATE!经过几天的挣扎,我自己找到了问题。

需要添加“自我”。在“点击”之前。删除了“root = tk()”,删除了“从tkinter import *”并添加了“tk”。对于每个按钮,检查按钮,标签和框架,现在它终于工作了。代码现在也已更新。

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()

0 个答案:

没有答案