首页 > 解决方案 > 尝试在 Python 中关闭 Tkinter 窗口时发生 TypeError

问题描述

我目前正在为学校做一个课程项目,它是一个具有使用 Tkinter、Python 和 SQLite3 的用户界面的数据库系统。我使用此功能关闭窗口,但显示以下错误。我附上了一段代码和一张表格的照片。

Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“C:\Users\Ryan\AppData\Local\Programs\Python\Python38-32\lib\tkinter_ init _.py”,第 1883 行,调用 返回 self。 func(*args) TypeError: quit() 接受 0 个位置参数,但给出了 1 个

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

from PIL import Image, ImageTk

import CustomerForm_support
import os.path
import sqlite3
import tkinter.messagebox

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    global prog_location
    prog_call = sys.argv[0]
    prog_location = os.path.split(prog_call)[0]
    root = tk.Tk()
    top = CustomerForm (root)
    CustomerForm_support.init(root, top)
    root.mainloop()

w = None
def create_CustomerForm(rt, *args, **kwargs):
    '''Starting point when module is imported by another module.
       Correct form of call: 'create_CustomerForm(root, *args, **kwargs)' .'''
    global w, w_win, root
    global prog_location
    prog_call = sys.argv[0]
    prog_location = os.path.split(prog_call)[0]
    #rt = root
    root = rt
    w = tk.Toplevel (root)
    top = CustomerForm (w)
    CustomerForm_support.init(w, top, *args, **kwargs)
    return (w, top)


class CustomerForm:
    def quit():
        root.quit()

在此处输入图像描述

标签: pythonsqlitetkinter

解决方案


基本类错误。所有方法都必须将“self”作为第一个参数。

class CustomerForm:
    def quit(self):
        root.quit()

推荐阅读