当我使用CMD运行Python Tkinter窗口时,它不会打开

当我使用CMD运行Python Tkinter窗口时,它不会打开,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,如果我在空闲状态下运行代码,它可以正常工作,但是当我尝试使用CMD或pyinstaller执行它时,它不会创建窗口。我不确定这是否是因为我遗漏了什么,我也研究了其他问题,但似乎没有任何帮助 我的自定义模块只提供数据并生成主窗口 它打印所有内容,但不生成窗口。我想不出是怎么回事,如果能帮上忙,我将不胜感激 import sqlite3 import tkinter from tkinter import * from tkinter import messagebox import request

如果我在空闲状态下运行代码,它可以正常工作,但是当我尝试使用CMD或pyinstaller执行它时,它不会创建窗口。我不确定这是否是因为我遗漏了什么,我也研究了其他问题,但似乎没有任何帮助

我的自定义模块只提供数据并生成主窗口

它打印所有内容,但不生成窗口。我想不出是怎么回事,如果能帮上忙,我将不胜感激

import sqlite3
import tkinter
from tkinter import *
from tkinter import messagebox
import requests
import webbrowser
import win32api
import sys
import os

#custom Modules
import Info
import Till
import Shop
import Error


home = os.path.expanduser('~')

__author__ = Info.i_author
__copyright__ = Info.i_copyright
__credits__ = Info.i_credits
__license__ = Info.i_license
version = Info.i_version
__maintainer__ = Info.i_maintainer
__email__ = Info.i_email
__status__ = Info.i_status

_AppName_ = Info.i_AppName_

Downloads_location = os.path.join(home, 'Downloads')

conn = sqlite3.connect('Shop_Database.db')
c = conn.cursor()

def Create_Tables():
    c.execute('''CREATE TABLE IF NOT EXISTS CRJ(ID REAL,Day INTEGER,Month INTEGER,Year INTEGER,Time INTEGER, Date INTEGER, Description TEXT, Amount RAEL, Bank RAEL, Item TEXT, QTY TEXT, Payment_Type TEXT, Cashier TEXT)''')
    c.execute('''CREATE TABLE IF NOT EXISTS "Sales" (
                            "ID"    INTEGER,
                            "Day"   INTEGER,
                            "Month" INTEGER,
                            "Year"  INTEGER,
                            "Time"  INTEGER,
                            "Date"      INTEGER,
                            "Item"  TEXT,
                            "Price" INTEGER,
                            "Qty"   INTEGER,
                            "Weight" REAL)''')
    c.execute('''CREATE TABLE IF NOT EXISTS Product_List(Code INT, Price REAL, Item TEXT, Cost_Price REAL)''')
    c.execute('''CREATE TABLE IF NOT EXISTS Customer_List(Code REAL, Name TEXT)''')
    c.execute('''CREATE TABLE IF NOT EXISTS MenuS(Menu_Name TEXT, Menu_Number RAEL)''')
    c.execute('''CREATE TABLE IF NOT EXISTS Cashiers(ID REAL, Name TEXT, Password TEXT, Permision REAL)''')
    c.execute('''CREATE TABLE IF NOT EXISTS Scale(Code INTEGER, Name TEXT, Price_per_kg REAL)''')
    c.execute('''CREATE TABLE IF NOT EXISTS Settings(ID REAL, Name TEXT, Value REAL, OTHER TEXT)''')

Create_Tables()

R = Shop




def Login_Page():
    Login_page = Tk()
    Login_page.title("Login Page")
    Login_page.configure(background="cadet blue")
    Login_page.attributes("-fullscreen", True)
    Login_page.attributes('-topmost', True)


    X_Distance = 600

    F1 = Frame(Login_page, bd=8, relief="raise")
    F1.place(x=180+X_Distance,y=300)
    Label(F1, text="Password", bd=2).pack(side="top")
##    e1 = Text(F1, height=1, width=15)
    e1 = Entry(F1, bd=2, width=15)
    e1.pack(side="top")


    LbN1 = Listbox(F1)
    c.execute("SELECT * FROM Cashiers")
    for row in c.fetchall():
##        print(row)
##        print(row[1])
        Name = row[1]
        LbN1.insert(1, Name)
    
    
    def K9():
        e1.insert(INSERT, "9")
    def K8():
        e1.insert(INSERT, "8")
    def K7():
        e1.insert(INSERT, "7")
    def K6():
        e1.insert(INSERT, "6")
    def K5():
        e1.insert(INSERT, "5")
    def K4():
        e1.insert(INSERT, "4")
    def K3():
        e1.insert(INSERT, "3")
    def K2():
        e1.insert(INSERT, "2")
    def K1():
        e1.insert(INSERT, "1")
    def K0():
        e1.insert(INSERT, "0")
    def K():
        e1.insert(INSERT, ".")
    def K10():
        e1.delete(1.0, 1000.0)
        
    F101 = Frame(Login_page, bd=8, bg="grey", relief="raise")
    F101.place(x=X_Distance,y=300)

    scale_1 = 3

    W = 2*scale_1
    H = 1*scale_1

    Button(F101, text="9", width=W, height=H, bg="blue", fg="white", command=K9, bd=2).grid(row=1,column=2)
    Button(F101, text="8", width=W, height=H, bg="blue", fg="white", command=K8, bd=2).grid(row=1,column=1)
    Button(F101, text="7", width=W, height=H, bg="blue", fg="white", command=K7, bd=2).grid(row=1,column=0)
    Button(F101, text="6", width=W, height=H, bg="blue", fg="white", command=K6, bd=2).grid(row=2,column=2)
    Button(F101, text="5", width=W, height=H, bg="blue", fg="white", command=K5, bd=2).grid(row=2,column=1)
    Button(F101, text="4", width=W, height=H, bg="blue", fg="white", command=K4, bd=2).grid(row=2,column=0)
    Button(F101, text="3", width=W, height=H, bg="blue", fg="white", command=K3, bd=2).grid(row=3,column=2)
    Button(F101, text="2", width=W, height=H, bg="blue", fg="white", command=K2, bd=2).grid(row=3,column=1)
    Button(F101, text="1", width=W, height=H, bg="blue", fg="white", command=K1, bd=2).grid(row=3,column=0)
    Button(F101, text="0", width=W, height=H, bg="blue", fg="white", command=K0, bd=2).grid(row=4,column=1)
    Button(F101, text=".", width=W, height=H, bg="blue", fg="white", command=K, bd=2).grid(row=4,column=0)
    Button(F101, text="C", width=W, height=H, bg="blue", fg="white", command=K10, bd=2).grid(row=4,column=2)
    Label(F1, text="_______________________", bd=2).pack(side="top")
    Label(F1, text="User", bd=2).pack(side="top")
    LbN1.pack(side="top")

    def ENTER():
        try:
            User = LbN1.get(LbN1.curselection())
        except:
            MsgBox_003 = messagebox.showerror ('ERROR',Error.Error_003,icon = Error.Error_icon)
        print(User)
        c.execute("SELECT * FROM Cashiers WHERE Name = ?",(User,))
        for row in c.fetchall():
            Password = str(e1.get())
            A = (row[2])
            if Password == A:
                print("Password OK")
                Login_page.destroy()
                if (row[3]) == 1.0:
                    R.LEV1(User)
                elif (row[3]) == 2.0:
                    R.LEV2(User)
                elif (row[3]) == 3.0:
                    R.LEV3(User)
            else:
                print("NO")
                MsgBox_002 = messagebox.showerror ('ERROR',Error.Error_002,icon = Error.Error_icon)

    Button(Login_page, text="Done", width=10, height=1, bg="blue", fg="white", command=ENTER, bd=2).place(x=180+X_Distance,y=560)


def Update():
    win32api.ShellExecute(0, 'open', '{Downloads_location}\\setup.msi', None, None, 10)

def Update_manager(TEXT="Checking for update"):
    Update_Manager = Tk()
    Update_Manager.title(TEXT)
    Update_Manager.configure(background="#BEBEBE")
    Update_Manager.attributes("-topmost", True)
    label = Label(Update_Manager, text=(TEXT+"\n\nMade By Connor Hess  V" + str(version)), fg="white", bg="gray").pack()
    
    response = requests.get('https://raw.githubusercontent.com/connorhess/EasyPOS/master/version.txt')
    data = response.text
    print(data)
    if float(data) > version:
        MsgBox = messagebox.askquestion ('Update!', f'{_AppName_} {version} needs to update to version {data}',icon = 'warning')
        if MsgBox == 'yes':
            webbrowser.open_new_tab('https://github.com/connorhess/EasyPOS/raw/master/'
                                                'Update/Output/setup.exe?raw=true')
            Update_Manager.destroy()
            Update()
        else:
            Update_Manager.destroy()
            Login_Page()
    else:
        Update_Manager.destroy()
        Login_Page()



try:
    c.execute("SELECT * FROM Cashiers")
    for row in c.fetchall():
##        print("H")
        pass
    Update()
except:
    print("First Time")
    Create_Tables()
    Till.add_account()
    Update()
它没有给出错误消息

如果您需要我的其他模块的任何数据,请告诉我

#custom Modules
import Info
import Till
import Shop
import Error

如果是因为
mainloop
我将
mainloop
函数放在哪里

您缺少
mainloop()
函数。它应该放在GUI创建的末尾。

我应该把它放在哪里mainloop@Connor它应该放在GUI语句的末尾——假设您正在创建主屏幕,它应该放在那里。如果你给我一些时间,我会仔细阅读整个代码,并试图找到它应该放在哪里,但我更希望你能深入了解它如果我使用的是toplevel,我需要为每个代码执行mainloop吗toplevel@Connor不可以。在每个Tkinter应用程序中,应该正好有一个
mainloop()
函数的调用。好的,谢谢。您是否也可以帮助我执行此
无法调用“event”命令:应用程序在执行从“ttk::ThemeChanged”中调用的“event generate$w”(过程“ttk::ThemeChanged”第6行)时已被销毁
请将此代码缩减为一个完整的代码。例如,如果窗口出现问题,我们不需要任何数据库代码,而且可能只需要一个按钮而不是一打按钮。