import sys
from tkinter import *
def print():
print("Encoded " + message + " with " + offset)
gui = Tk()
gui.title("Caesar Cypher Encoder")
Button(gui, text="Encode", command=encode).grid(row = 2, column = 2)
Label(gui, text = "Message").grid(row = 1, column =0)
Label(gui, text = "Offset").grid(row = 1, column =1)
message = Entry(gui).grid(row=2, column=0)
offset = Scale(gui, from_=0, to=25).grid(row=2, column=1)
mainloop( )
当我在输入框中输入一个输入并在滑块上输入一个值来运行此代码时 - 它会出现错误
>>>Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:/Users/xxxx/Desktop/Code/Functionised/GUI.pyw", line 5, in encode
print("Encoded " + message + " with " + offset)
TypeError: Can't convert 'NoneType' object to str implicitly
顺便说一下,使用简单的 str() 是行不通的
EDIT
使用新代码
import sys
from tkinter import *
def printer():
print(message)
print(offset)
gui = Tk()
gui.title("Caesar Cypher Encoder")
Button(gui, text="Encode", command=printer).grid(row = 2, column = 2)
Label(gui, text = "Message").grid(row = 1, column =0)
Label(gui, text = "Offset").grid(row = 1, column =1)
message = Entry(gui)
message.grid(row=2, column=0)
offset = Scale(gui, from_=0, to=25)
offset.grid(row=2, column=1)
mainloop( )
它返回
.46329264
.46329296
EDIT 2
def printer():
print(message.get())
print(offset.get())
这解决了 .xxxxxxxx 问题