Aug-24-2020, 03:05 PM
(This post was last modified: Aug-24-2020, 03:05 PM by SmukasPlays.)
I'm doing a program that has loads of windows that do different functions. But I don't know how to run more than run window together. When I'm running one and try to move for another, appears that "Windows stop responding" and it just end when I close the window that I'm in. How can I fix it? I'll post two example of code, one is to register and one is to update.
Register
Register
from tkinter import * from tkinter import ttk import tkinter.messagebox import sqlite3 from subprocess import call conn = sqlite3.connect("C:\TkinterVenda\Database\Cows.db") c = conn.cursor() class Secagem: def __init__(self, master): self.master = master self.heading = Label(master, text='Secagem', font='arial 40 bold', bg='medium slate blue') self.heading.place(x=300, y=0) self.Nome_L = Label(master, text='Nome:', font='arial 18 bold', bg='medium slate blue') self.Nome_L.place(x=0, y=70) self.Data_L = Label(master, text='Data da Secagem:', font='arial 18 bold', bg='medium slate blue') self.Data_L.place(x=0, y=120) self.Anls_L = Label(master, text='AnĂ¡lise OnFarm:', font='arial 18 bold', bg='medium slate blue') self.Anls_L.place(x=0, y=170) self.Produtos_L = Label(master, text='Produtos', font='arial 18 bold', bg='medium slate blue') self.Produtos_L.place(x=0, y=220) nomes = [] comando = "Select * FROM Cadastro" c.execute(comando) dados = c.fetchall() linhas = len(dados) for i in range(2, linhas): for j in range(2, 3): nomes.append(dados[i][j]) self.Nome_E = ttk.Combobox(master, width=20, font='arial 14 bold') self.Nome_E['values'] = nomes self.Nome_E.grid(column=1, row=0) self.Nome_E.place(x=250, y=80) ano = [] valores = [] for z in range(1, 32): valores.append(z) for d in range(2010, 2026): ano.append(d) self.comb2 = ttk.Combobox(master, width=10, state='readonly') self.comb2['values'] = valores self.comb2.grid(column=1, row=0) self.comb2.place(x=250, y=130) self.comb = ttk.Combobox(master, width=10, state='readonly') self.comb['values'] = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] self.comb.grid(column=1, row=0) self.comb.place(x=380, y=130) self.comb3 = ttk.Combobox(master, width=10, state='readonly') self.comb3['values'] = ano self.comb3.grid(column=1, row=0) self.comb3.place(x=505, y=130) self.Anls_E = Entry(master, width=25, font='arial 18 bold') self.Anls_E.place(x=250, y=170) self.Produtos_E = Entry(master, width=25, font='arial 18 bold') self.Produtos_E.place(x=250, y=220) self.BotaoSalvar = Button(master, width=20, height=2, bg='DarkGoldenrod1', text='Salvar', activebackground='DarkGoldenrod1', cursor='hand2', command=self.save) self.BotaoSalvar.place(x=380, y=320) self.BotaoSalvar = Button (master, width=20, height=2, bg='PaleTurquoise1', text='Alterar', activebackground='PaleTurquoise1', cursor='hand2', command=self.secagemUPD) self.BotaoSalvar.place (x=600, y=320) self.master.bind("<Return>", self.save) def save(self,*args, **kwargs): dia = self.comb2.get () mes = self.comb.get () ano = self.comb3.get () dat = ano + '-' + mes + '-' + dia self.Nome = self.Nome_E.get() self.Data = dat self.Analise = self.Anls_E.get() self.Dia = dia self.Mes = mes self.Ano = ano self.Produtos = self.Produtos_E.get() sql = 'INSERT INTO Secagem (Nome, Data, Analise, Produto, Dia, Mes, Ano) VALUES(?,?,?,?,?,?,?)' c.execute(sql,(self.Nome, self.Data, self.Analise, self.Produtos, self.Dia, self.Mes, self.Ano)) conn.commit() tkinter.messagebox.showinfo("Provedor", "Dados Salvos Com Sucesso!") self.Nome_E.set('') self.comb.set('') self.comb2.set('') self.comb3.set('') self.Anls_E.delete(0, END) self.Produtos_E.delete(0, END) def search(self): search = "SELECT * FROM Secagem WHERE Nome = ?" result = c.execute (search, (self.Nome_E.get (),)) for r in result: self.n1 = r[1] self.n2 = r[2] self.n3 = r[3] self.n4 = r[4] self.n5 = r[5] self.n6 = r[6] self.n7 = r[7] self.clear() self.Nome_E.set(self.n1) self.comb2.set(self.n5) self.comb.set(self.n6) self.comb3.set(self.n7) self.Anls_E.insert(0, str(self.n3)) self.Produtos_E.insert(0, str(self.n4)) def clear(self): self.Nome_E.set('') self.comb2.set('') self.comb.set('') self.comb3.set('') self.Anls_E.delete(0, END) self.Produtos_E.delete(0, END) def secagemUPD(self): call(['python', 'SecagemUpd.py']) root = Tk() g = Secagem(root) root.configure(bg='medium slate blue') root.geometry('800x400+400+10') root.mainloop()Update:
from tkinter import * from tkinter import ttk import tkinter.messagebox import sqlite3 conn = sqlite3.connect("C:\TkinterVenda\Database\Cows.db") c = conn.cursor() class Secagem: def __init__(self, master): self.master = master self.heading = Label(master, text='Secagem', font='arial 40 bold', bg='medium slate blue') self.heading.place(x=300, y=0) self.Nome_L = Label(master, text='Nome:', font='arial 18 bold', bg='medium slate blue') self.Nome_L.place(x=0, y=70) self.Data_L = Label(master, text='Data da Secagem:', font='arial 18 bold', bg='medium slate blue') self.Data_L.place(x=0, y=170) self.Anls_L = Label(master, text='AnĂ¡lise OnFarm:', font='arial 18 bold', bg='medium slate blue') self.Anls_L.place(x=0, y=220) self.Produtos_L = Label(master, text='Produtos', font='arial 18 bold', bg='medium slate blue') self.Produtos_L.place(x=0, y=270) nomes = [] comando = "Select * FROM Secagem" c.execute(comando) dados = c.fetchall() linhas = len(dados) for i in range(2, linhas): for j in range(1, 2): nomes.append(dados[i][j]) self.Nome_E = ttk.Combobox(master, width=20, font='arial 14 bold') self.Nome_E['values'] = nomes self.Nome_E.grid(column=1, row=0) self.Nome_E.place(x=250, y=80) self.BotaoPesquisar = Button (master, width=25, height=2, bg='Orange', text='Pesquisar', activebackground='Orange', cursor='hand2', command=self.search) self.BotaoPesquisar.place (x=400, y=120) ano = [] valores = [] for z in range(1, 32): valores.append(z) for d in range(2010, 2026): ano.append(d) self.comb2 = ttk.Combobox(master, width=10, state='readonly') self.comb2['values'] = valores self.comb2.grid(column=1, row=0) self.comb2.place(x=250, y=180) self.comb = ttk.Combobox(master, width=10, state='readonly') self.comb['values'] = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] self.comb.grid(column=1, row=0) self.comb.place(x=380, y=180) self.comb3 = ttk.Combobox(master, width=10, state='readonly') self.comb3['values'] = ano self.comb3.grid(column=1, row=0) self.comb3.place(x=505, y=180) self.Anls_E = Entry(master, width=25, font='arial 18 bold') self.Anls_E.place(x=250, y=220) self.Produtos_E = Entry(master, width=25, font='arial 18 bold') self.Produtos_E.place(x=250, y=270) self.BotaoAtualizar = Button (master, width=20, height=2, cursor='hand2', text='Atualizar', bg='grey', activebackground='grey', command=self.update) self.BotaoAtualizar.place (x=550, y=320) self.master.bind("<Return>", self.update) def search(self): search = "SELECT * FROM Secagem WHERE Nome = ?" result = c.execute (search, (self.Nome_E.get (),)) for r in result: self.n1 = r[1] self.n2 = r[2] self.n3 = r[3] self.n4 = r[4] self.n5 = r[5] self.n6 = r[6] self.n7 = r[7] self.n8 = r[8] self.clear() self.Nome_E.set(self.n1) self.comb2.set(self.n5) self.comb.set(self.n6) self.comb3.set(self.n7) self.Anls_E.insert(0, str(self.n3)) self.Produtos_E.insert(0, str(self.n4)) def clear(self): self.Nome_E.set('') self.comb2.set('') self.comb.set('') self.comb3.set('') self.Anls_E.delete(0, END) self.Produtos_E.delete(0, END) def update(self): dia = self.comb2.get () mes = self.comb.get () ano = self.comb3.get () dat = ano + '-' + mes + '-' + dia self.u1 = self.Nome_E.get () self.u2 = dat self.u3 = self.Anls_E.get() self.u4 = self.Produtos_E.get() self.u5 = dia self.u6 = mes self.u7 = ano UPD = "UPDATE Secagem SET Nome = ?, Data = ?, Analise = ?, Produto = ?, Dia = ?, Mes = ?, Ano = ? WHERE " \ "ID = ?" c.execute (UPD, (self.u1, self.u2, self.u3, self.u4, self.u5, self.u6, self.u7, self.n8,)) conn.commit () tkinter.messagebox.showinfo ("Provedor", "Dados Atualizados Com Sucesso!") self.clear () root = Tk() g = Secagem(root) root.configure(bg='medium slate blue') root.geometry('800x400+500+50') root.mainloop()