Python Tkinter How can i open another window with classes












0















I have two .py classes . loginC.py and mainC.py. They are different files in a project folder.



You can see in here



I have some conditions in my LoginC class.It is 'def loginB_clicked(self)' method. If my login info is correct ,else condition of that method executes and open main window.



My LoginC.py is :



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**


My mainC.py is :



from tkinter import *
import sqlite3

class mainC:
def __init__(self,main):
ok_B = Button(main, text="Main Button")
ok_B.pack()

mainW = Tk()
m = mainC(mainW)
mainW.title("Main Form")
mainW.mainloop()









share|improve this question

























  • The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

    – figbeam
    Nov 21 '18 at 14:31











  • @figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

    – Bryan Oakley
    Nov 21 '18 at 14:40











  • Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

    – figbeam
    Nov 21 '18 at 14:46











  • @BryanOakley : What is the usual way ? Can you explain or share a link ?

    – Can Şahin
    Nov 22 '18 at 11:18











  • @CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

    – Bryan Oakley
    Nov 22 '18 at 13:54
















0















I have two .py classes . loginC.py and mainC.py. They are different files in a project folder.



You can see in here



I have some conditions in my LoginC class.It is 'def loginB_clicked(self)' method. If my login info is correct ,else condition of that method executes and open main window.



My LoginC.py is :



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**


My mainC.py is :



from tkinter import *
import sqlite3

class mainC:
def __init__(self,main):
ok_B = Button(main, text="Main Button")
ok_B.pack()

mainW = Tk()
m = mainC(mainW)
mainW.title("Main Form")
mainW.mainloop()









share|improve this question

























  • The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

    – figbeam
    Nov 21 '18 at 14:31











  • @figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

    – Bryan Oakley
    Nov 21 '18 at 14:40











  • Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

    – figbeam
    Nov 21 '18 at 14:46











  • @BryanOakley : What is the usual way ? Can you explain or share a link ?

    – Can Şahin
    Nov 22 '18 at 11:18











  • @CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

    – Bryan Oakley
    Nov 22 '18 at 13:54














0












0








0








I have two .py classes . loginC.py and mainC.py. They are different files in a project folder.



You can see in here



I have some conditions in my LoginC class.It is 'def loginB_clicked(self)' method. If my login info is correct ,else condition of that method executes and open main window.



My LoginC.py is :



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**


My mainC.py is :



from tkinter import *
import sqlite3

class mainC:
def __init__(self,main):
ok_B = Button(main, text="Main Button")
ok_B.pack()

mainW = Tk()
m = mainC(mainW)
mainW.title("Main Form")
mainW.mainloop()









share|improve this question
















I have two .py classes . loginC.py and mainC.py. They are different files in a project folder.



You can see in here



I have some conditions in my LoginC class.It is 'def loginB_clicked(self)' method. If my login info is correct ,else condition of that method executes and open main window.



My LoginC.py is :



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**


My mainC.py is :



from tkinter import *
import sqlite3

class mainC:
def __init__(self,main):
ok_B = Button(main, text="Main Button")
ok_B.pack()

mainW = Tk()
m = mainC(mainW)
mainW.title("Main Form")
mainW.mainloop()






python class tkinter window






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:16









Dave

2,24451625




2,24451625










asked Nov 21 '18 at 13:37









Can ŞahinCan Şahin

1




1













  • The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

    – figbeam
    Nov 21 '18 at 14:31











  • @figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

    – Bryan Oakley
    Nov 21 '18 at 14:40











  • Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

    – figbeam
    Nov 21 '18 at 14:46











  • @BryanOakley : What is the usual way ? Can you explain or share a link ?

    – Can Şahin
    Nov 22 '18 at 11:18











  • @CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

    – Bryan Oakley
    Nov 22 '18 at 13:54



















  • The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

    – figbeam
    Nov 21 '18 at 14:31











  • @figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

    – Bryan Oakley
    Nov 21 '18 at 14:40











  • Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

    – figbeam
    Nov 21 '18 at 14:46











  • @BryanOakley : What is the usual way ? Can you explain or share a link ?

    – Can Şahin
    Nov 22 '18 at 11:18











  • @CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

    – Bryan Oakley
    Nov 22 '18 at 13:54

















The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

– figbeam
Nov 21 '18 at 14:31





The usual way of switching windows is described in this answer: Switch between two frames in tkinter.

– figbeam
Nov 21 '18 at 14:31













@figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

– Bryan Oakley
Nov 21 '18 at 14:40





@figbeam: that's not the usual way. Lots of people use it, but personally I don't recommend it as a good general purpose solution (and I wrote that answer!).

– Bryan Oakley
Nov 21 '18 at 14:40













Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

– figbeam
Nov 21 '18 at 14:46





Sorry, my bad for not reading all the comments. There is a list of starting pionts though.

– figbeam
Nov 21 '18 at 14:46













@BryanOakley : What is the usual way ? Can you explain or share a link ?

– Can Şahin
Nov 22 '18 at 11:18





@BryanOakley : What is the usual way ? Can you explain or share a link ?

– Can Şahin
Nov 22 '18 at 11:18













@CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

– Bryan Oakley
Nov 22 '18 at 13:54





@CanŞahin: there is no "usual way". The way to do it is part personal preference, part driven by your requirements, architecture, and UI design.

– Bryan Oakley
Nov 22 '18 at 13:54












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413297%2fpython-tkinter-how-can-i-open-another-window-with-classes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413297%2fpython-tkinter-how-can-i-open-another-window-with-classes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith