Python Tkinter如何打开带有类的另一个窗口

时间:2018-11-21 13:37:38

标签: python class tkinter window

我有两个.py类。 loginC.py和mainC.py。它们是项目文件夹中的不同文件。

You can see in here

我的LoginC类中有一些条件,这是'def loginB_clicked(self)'方法。如果我的登录信息正确,则执行该方法的其他条件并打开主窗口。

我的LoginC.py是:

T-SQL

我的mainC.py是:

import sqlite3
from tkinter import *
import time
from PIL import Image,ImageTk
from tkinter import  messagebox

    class loginC:
        def __init__(self,login):

            self.loadP = Image.open("C:\\PythonProject\\PycharmProjects\\ProductCost\\images\\login.png")
            self.render = ImageTk.PhotoImage(self.loadP)
            self.img = Label(login, image=self.render)
            self.img.image = self.render
            self.img.place(x=275, y=65)
            self.img.configure(background="lightgrey")

            userInfo_L = Label(login, text="Kullanıcı Giriş Bilgileri", fg="black", bg="lightgrey",
                       font=("Calibri", "10", "bold underline")).place(x=30, y=65)
            userName_L = Label(login, text="Kullanıcı Adı :", fg="black", bg="lightgrey",
                       font=("Calibri", "10", "bold")).place(x=30, y=100)
            password_L = Label(login, text="Parola :", fg="black", bg="lightgrey", font=("Calibri", "10", "bold")).place(x=60, y=125)

            self.userName_E = Entry(login)
            self.userName_E.place(x=120, y=100)
            self.userName_E.focus()

            self.password_E = Entry(login,show="*")
            self.password_E.place(x=120, y=125)

            self.login_B = Button(login, text="Giriş", width=10, font=("Calibri", "10", "bold"),command=self.loginB_clicked).place(x=140, y=160)

            self.loginStatus_L = Label(login, text="", fg="black", bg="lightgrey",anchor='e', font=("Calibri", "10", "bold"))
            self.loginStatus_L.pack(side = "bottom", fill = "both")

def loginB_clicked(self):

    if self.userName_E.get()=="" or  self.password_E.get()=="":
        messagebox.showwarning("WARNING","FIELDS ARE NULL !")
    else:

        userName=self.userName_E.get()
        password=self.password_E.get()
        conn=sqlite3.connect("ProductCost.db")
        self.cursor=conn.cursor()
        self.cursor.execute("SELECT * FROM USER WHERE userName=? and password=?",(userName,password))
        userList=self.cursor.fetchall()
        if len(userList)==0:
            messagebox.showerror("ERROR TITLE", "ERROR!")
        else:
            pass
            **I WANT TO CALL MY mainC.py FOR OPEN MAIN WINDOW**

0 个答案:

没有答案