Eme*_*lan 2 python tkinter python-3.x
#-*- coding: cp857 -*-
from tkinter import *
###########################################################
root=Tk()
root.title("MY FILM ARCHIVE")
root.resizable(False, False)
###########################################################
def add():
db = open(r"C:\Users\PC\Desktop\db.txt", "a+")
enter=input("Enter your's film: "),
db.write(enter + "\n")
db.close()
db.flush()
button=Button(text="Add Film!",command=add, font=("Flux",15, "bold"))
button.pack(expand="yes", anchor="center")
mainloop()
Run Code Online (Sandbox Code Playgroud)
当我运行该程序并按下按钮时,出现以下错误:(
TypeError: can only concatenate tuple (not "str") to tuple
Run Code Online (Sandbox Code Playgroud)
该行末尾的逗号:
enter=input("Enter your's film: "),
Run Code Online (Sandbox Code Playgroud)
使其相当于:
enter = (input("Enter your's film: "),)
Run Code Online (Sandbox Code Playgroud)
其中存储一个一元组enter。去掉逗号就可以了。