我需要将此函数中的打印输入tkinter pag

2024-10-04 05:25:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个功能,可以打印25行文本,我需要在tkinter页面中输入,但每次都不起作用

我试过使用text.input,但似乎不起作用

这是我需要打印的函数:

def decode(secretmessage):
    for key in range(len(alphabet)):
        newAlp = alphabet[key:] + alphabet[:key]
        attempt = ""
        for i in range(len(message)):
            index = alphabet.find(message[i])
            if index < 0:
                attempt += message[i]
            else:
                attempt += newAlp[index]
        print("Key: " + str(key) + " - " + attempt)
        print()

这就是我所尝试的:

def finalprint (uncoded):
    print("Key: " + str(key) + " - " + attempt)
    print()

text = Text.insert(root, finalprint(message), width=450, height=450)

因为某种原因出现是行不通的


Tags: keytextinmessageforindexlendef
1条回答
网友
1楼 · 发布于 2024-10-04 05:25:17

print命令将给定的文本打印到控制台。它确实返回None

您的finalprint函数还返回None,而Text.insert需要一个字符串作为输入

您可以将值存储到字符串中,而不是打印输出

def finalprint(uncoded): ## may need different inputs as key and attempts are not in scope
    string =  ""
    string = string + "Key: " + str(key) + " - " + attempts + "\n"
    return string

然而,finalprint函数的输入是未编码的,而其中使用的变量是键和尝试。您可能需要向函数传递更多信息,使其像您编写的那样工作

相关问题 更多 >