Error in transition of Tkinter screens

Asked

Viewed 110 times

0

Hello I’m new to python and I’m developing an application that has access to dblite3, I managed to add another screen more when I make a connection with my db it goes back to home screen, I wanted him to focus only on one screen and return to the home screen only when it was closed.

from tkinter import *
import tkinter as tk
from datetime import datetime
from tkinter import messagebox
import sqlite3


conn = sqlite3.connect("C:\sheepDown\BaseDate\dbsheep.db")
c = conn.cursor()

result = c.execute("SELECT MAX(idp) from produtos")
for rec in result:
    idp = rec[0]



now = datetime.now()

datatual = now.strftime("%d/%m/%Y %H:%M:%S")

class inicio:
    def __init__(self, primeiro):
        self.primeiro = primeiro

        self.primeiro_ph = PhotoImage(file="prime.gif")
        self.lab = Label(primeiro, image=self.primeiro_ph)
        self.lab.place(x=400, y=100)




        self.btn_inicio = Button(primeiro, text="INICIO", width=30, bg='LawnGreen', fg='white', font='arial 10', command=self. pri_jan)
        self.btn_inicio.place(x=190, y=20)

        self.btn_pend = Button(primeiro, text="PENDENCIAS", width=30, bg='red', fg='white',  font='arial 10')
        self.btn_pend.place(x=530, y=20)

        self.btn_cad = Button(primeiro, text="CADASTROS", width=30, bg='DeepSkyBlue', fg='white', font='arial 10', command=self.new_jan)
        self.btn_cad.place(x=870, y=20)

        self.list = Listbox(primeiro, width=32, height=1)
        self.list.insert(0, )
        self.list.place(x=550, y=490)
        self.list.insert(END, "DATA E HORA : " + str(datatual))
#JANELA============CADASTROS

    def new_jan(self):


        cad = Tk()
        self.clab = Label(cad, text="CADASTRO DE PRODUTOS", font=('arial 30 bold '), fg='black')
        self.clab.place(x=400, y=0)
        cad.geometry('1366x768+0+0')

        self.texb = Text(cad, width=60, height=30, )
        self.texb.place(x=700, y=148)
        self.texb.insert(END, "DATA E HORA DO ULTIMO PRODUTO: " + str(datatual))

        self.nomepr = Label(cad, text="NOME", font=('arial 17 bold'), fg='black')
        self.nomepr.place(x=15, y=150)
        self.nomepr['bg'] = 'LightCyan'

        self.nomepr_e = Entry(cad, width=20, font=('arial 15 '))
        self.nomepr_e.place(x=300, y=150)

        self.valorp = Label(cad, text="VALOR", font=('arial 17 bold'), fg='black')
        self.valorp.place(x=15, y=290)
        self.valorp['bg'] = 'LightCyan'

        self.valorpr_e = Entry(cad, width=8, font=('arial 15 '))
        self.valorpr_e.place(x=300, y=300)

        self.quantidade = Label(cad, text="QUANTIDADE", font=('arial 17 bold'), fg='black')
        self.quantidade.place(x=15, y=220)
        self.quantidade['bg'] = 'LightCyan'

        self.quantidade_e = Entry(cad, width=8, font=('arial 15 '))
        self.quantidade_e.place(x=300, y=220)

        self.btn_adc = Button(cad, text="Cadastrar", width=15, bg='steelblue', fg='white', command=self.getcli_items)
        self.btn_adc.place(x=300, y=400)

        self.btn_clear = Button(cad, text="Limpar", width=15, bg='Firebrick1', fg='white', command=self.limp_cli)
        self.btn_clear.place(x=470, y=400)

    def getcli_items(self, *args, **kwargs):
        self.nomepr = self.nomepr_e.get()
        self.valorpr = self.valorpr_e.get()
        self.quantidade = self.quantidade_e.get()

        if self.nomepr == '' or self.quantidade == '' or self.valorpr == '':
            messagebox.showinfo(title='PRIME-TI', message='PREENCHA TODOS OS CAMPOS')

        else:
            sql = "INSERT INTO produtos (nomepr, valorpr, quantidade) VALUES (?,?,?)"
            c.execute(sql, (self.nomepr, self.valorpr, self.quantidade))

            self.texb.insert(END, "\n\nO PRODUTO  " + str(self.nomepr) + " FOI CADASTRADO NO BANCO DE DADOS ")

            messagebox.showinfo(title='PRIME-TI',
                                message='PRODUTO : ' + str(self.nomepr) + '\n\nNO VALOR DE R$: ' + str(
                                    self.valorpr) + '\n\nNA QUANTIDADE DE : ' + str(self.quantidade))



    def limp_cli(self, *args, **kwargs):

        self.nomepr_e.delete(0, END)
        self.valorpr_e.delete(0, END)
        self.quantidade_e.delete(0, END)

1 answer

0

I advise you not to use Tkinter but Pyside2. Pyside2 features Qt5 with Qt Designer, a drag-and-drop Graphical User Interface creation IDE.

Acesse o site: https://pypi.org/project/PySide2/

To install just open the command prompt as administrator paste the following code, hit Enter and wait for the download and installation.

pip install PySide2

After installed look for the "designer.exe" inside the Python folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.