Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter TypeError:类型为';非类型';没有len()_Python_User Interface_Tkinter - Fatal编程技术网

Python tkinter TypeError:类型为';非类型';没有len()

Python tkinter TypeError:类型为';非类型';没有len(),python,user-interface,tkinter,Python,User Interface,Tkinter,我已经做了一个程序,当你可以决定在一个规模,多少字,你想要的。当我在天平上取1,然后尝试在标签上打印时,我得到错误: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Users\Eduard\Desktop\Zeugs

我已经做了一个程序,当你可以决定在一个规模,多少字,你想要的。当我在天平上取1,然后尝试在标签上打印时,我得到错误:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Users\Eduard\Desktop\Zeugs\python\test.py", line 69, in ok3
label['text']=random.choice(WORDS)
File "C:\Python33\lib\random.py", line 249, in choice
i = self._randbelow(len(seq))
TypeError: object of type 'NoneType' has no len()
代码如下:

import tkinter as tk
from tkinter import *
import random
from functools import partial

class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        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 (mode2, scale1):
            frame= F(container, self)
            self.frames[F]=frame
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(mode2)

    def show_frame(self, c):
        frame=self.frames[c]
        frame.tkraise()

class mode2(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        def antmenge(self):
            label1["text"]="Mögliche Antworten: " \
                + str(antmengen.get()) + " "

        label1=tk.Label(self, text="Mögliche Antworten: 0 Wörter", width=25)
        label1.pack()

        antmengen=IntVar()
        antmengen.set(0)

        antm=Scale(self, width=20, length=200, orient="vertical", from_=0, to=20,
        resolution=1, tickinterval=10, label="Wörter", command=antmenge(self),
        variable=antmengen)
        antm.pack()

        def abfrage():
            if antmengen.get()==1:
                button3=Button(self, text="push again", command=lambda: controller.show_frame(scale1))
                button3.pack()

        button2=tk.Button(self, text="push", command=abfrage)
        button2.pack()

class scale1(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label1=Label(self, text="Wort1")
        label1.pack()
        wort1auf=Entry(self)
        wort1auf.pack()

        label=tk.Label(self, text=" ")
        label.pack()

        a=label.configure(text=(wort1auf.get()))

        def ok3(label):
            WORDS=(a)
            label['text']=random.choice(WORDS)

        button1=tk.Button(self, text="push", command=partial(ok3, label))
        button1.pack()

if __name__== "__main__":
    app=SampleApp()
    app.mainloop()
对不起,如果我的英语不好。

好的

所以开始吧

    a=label.configure(text=(wort1auf.get()))
    def ok3(label):
        WORDS=(a)
        label['text']=random.choice(WORDS)
你犯错误的原因是,a和单词都是零 因为label.configure(…)返回None

我认为单词应该是一个单词列表,可以从中选择。我不知道你的“a”是什么意思,你想用输入词填充它吗?如果是这样的话,WORDS=(a)就可以了,但是你必须把“a”移到“ok3”里面

第二。它应该检索输入的值

    def ok3(label):
        WORDS=(wort1auf.get()) # this will choose a random letter out of your input. 
        #WORDS=(wort1auf.get(),) # this will choose a the input word, since it is the only word inside the tuple. 
        WORDS=(a)
        label['text']=random.choice(WORDS)
希望这有帮助 LG
Daniel

请回答您的问题并包含回溯的全文。您是否不理解错误消息,或者不理解对象为什么为
?请使用
打印
查看您在变量
a
中分配给
单词的内容。感谢您的快速回答,这可能是重复的。现在理解它对我有很大帮助。我还会说德语,如果你有问题,可以用德语问我;)
    def ok3(label):
        WORDS=(wort1auf.get()) # this will choose a random letter out of your input. 
        #WORDS=(wort1auf.get(),) # this will choose a the input word, since it is the only word inside the tuple. 
        WORDS=(a)
        label['text']=random.choice(WORDS)