自学小白,这段代码之前没什么问题,最近运行突然报错,不知道如何解决,求大腿解答。
报错为:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "E:/pythonProject2/自建窗口.py", line 50, in fanyi
d_list = list(set(a_list) ^ set(b_list))
TypeError: 'float' object is not iterable
import requests
from requests.exceptions import RequestException
import tkinter as tk
class Translate():
def __init__(self):
self.window = tk.Tk()
self.window.title("制作")
self.window.resizable(0,0)
self.input = tk.Entry(self.window, width=80)
self.info = tk.Text(self.window, height=18)
self.t_button = tk.Button(self.window, text='制作', relief=tk.RAISED, width=8, height=1, command=self.fanyi)
self.c_button1 = tk.Button(self.window, text='清空输入', relief=tk.RAISED, width=8, height=1, command=self.cle_e)
self.c_button2 = tk.Button(self.window, text='清空输出', relief=tk.RAISED,width=8, height=1, command=self.cle)
def gui_arrang(self):
self.input.grid(row=0,sticky="W",padx=1)
self.info.grid(row=1)
self.t_button.grid(row=0,column=1,padx=2)
self.c_button1.grid(row=0, column=2, padx=2)
self.c_button2.grid(row=0,column=3,padx=2)
def fanyi(self):
original_str = self.input.get()
if __name__ == '__main__':
a_list = [101, 102, 103, 104, 105, 106, 107, 108, 111, 112, 113, 114, 115, 201, 202, 203, 204, 205, 206,
207, 208, 211, 212, 213, 214, 215, 216, 301, 302, 303, 304, 305, 306, 307, 308, 311, 312, 313,
314, 315, 316, 401, 402, 403, 404, 405, 406, 407, 408, 505, 506, 507, 508, 515, 516, 411, 412,
413, 414, 415, 416, 511, 512, 513, 514]
b_list = eval(original_str)
c_list = [101, 102, 103, 104, 105, 106, 107, 108, 111, 112, 113, 114, 115, 201, 202, 203, 204, 205, 206,
207, 208, 211, 212, 213, 214, 215, 216, 301, 302, 303, 304, 305, 306, 307, 308, 311, 312, 313,
314, 315, 316, 401, 402, 403, 404, 405, 406, 407, 408, 505, 506, 507, 508, 515, 516]
d_list = list(set(a_list) ^ set(b_list))
ret_list = list((set(c_list).union(set(d_list))) ^ (set(c_list) ^ set(d_list)))
ret_list.sort()
self.info.delete(1.0, "end")
self.info.insert('end',ret_list)
def cle(self):
self.info.delete(1.0,"end")
def cle_e(self):
self.input.delete(0,"end")
def main():
t = Translate()
t.gui_arrang()
tk.mainloop()
if __name__ == '__main__':
main()