0
> import tkinter
> import tkinter as tk
> from tkinter import ttk
> from tkinter import messagebox
> import sqlite3

# CREEAREA APLICATIEI + CONFIGURAREA ACESTEIA

root = tk.Tk()
root.title("Raport 1.0d")

frame = tk.Frame(root)
frame.pack()


# FUNCTIONALITATE BUTON_TRIMITERE

def trimitere_date():

   nume_tehnician = nume_tehnician_dropdown.get()
   schimb = schimb_dropdown.get()
   linia = linia_dropdown.get()
   descriere_problema = descriere_problema_entry.get()
   durata_interventie = durata_interventie_entry.get()
   rezolvare_problema = rezolvare_problema_entry.get()

      if not all ([nume_tehnician, schimb, linia, descriere_problema, durata_interventie, rezolvare_problema]):
    messagebox.showerror("Eroare", " Completati toate campurile!")
    return

      else:
    messagebox.showinfo("Succes", " Datele au fost introduse cu succes!")
    print("Nume tehnician: " + nume_tehnician)

# GOLESTE INPUT-URILE DUPA CE S-A TRIMIS RAPORTUL

   descriere_problema_entry.delete(0, tk.END)
   durata_interventie_entry.delete(0, tk.END)
   rezolvare_problema_entry.delete(0, tk.END)

   info_frame = tk.LabelFrame(frame, text="Informatii USER/probleme")
   info_frame.grid(row=0, column=0, padx=20, pady=20)

# TABEL PENTRU BAZA DE DATE

# DESCHIDEREA BAZEI DE DATE

   conn = sqlite3.connect('raport_zilnic.db')
   tabel = '''CREATE TABLE IF NOT EXISTS raport_data
    (Nume_tehnician TEXT, Schimb TEXT, Linia TEXT,
        Descriere_problema TEXT, Durata_interventie TEXT,
        Rezolvare_problema TEXT)
    '''

   conn.execute(tabel)

#INSERARE DATE IN TABEL
   data_insert_query = '''INSERT INTO raport_zilnic (Nume_tehnician, Schimb, Linia, Descriere_problema, Durata_interventie, Rezolvare_problema) 
    VALUES (?, ?, ?, ?, ?, ?, ?)'''
    data_insert_tuple = (nume_tehnician, schimb, linia,
                    descriere_problmea, durata_interventie, rezolvare_problema )
   cursor = conn.cursor()
   cursor.execute(data_insert_query, data_insert_tuple)
   conn.commit()

# INCHIDEREA DATEI DE BAZA
   conn.close()

# CREEARE VARIABILELOR

   nume_tehnician_label = tk.Label(info_frame, text="Numele tehnician")
   nume_tehnician_dropdown = ttk.Combobox(info_frame, values=["nume1", "nume2", "nume3"])
   nume_tehnician_label.grid(row=0, column=0)
   nume_tehnician_dropdown.grid(row=1, column=0)

   schimb_label = tk.Label(info_frame, text="Schimbul")
   schimb_dropdown = ttk.Combobox(info_frame, values=["1", "2", "3"])
   schimb_label.grid(row=0, column=1)
   schimb_dropdown.grid(row=1, column=1)

   linia_label = tk.Label(info_frame, text="Linia")
   linia_dropdown = ttk.Combobox(info_frame, values=["LINIA1", "LINIA2", "LINIA3"])
   linia_label.grid(row=0, column=2)
   linia_dropdown.grid(row=1, column=2)

   descriere_problema_label = tk.Label(info_frame, text="Descrierea problemei")
   descriere_problema_label.grid(row=2, column=0)
   descriere_problema_entry = tk.Entry(info_frame)
   descriere_problema_entry.grid(row=3, column=0)

   durata_interventie_label = tk.Label(info_frame, text="Durata interventiei (in minute)")
   durata_interventie_label.grid(row=2, column=1)
   durata_interventie_entry = tk.Entry(info_frame)
   durata_interventie_entry.grid(row=3, column=1)

   rezolvare_problema_label = tk.Label(info_frame, text="Cum s-a rezolvat problema")
   rezolvare_problema_label.grid(row=2, column=2)
   rezolvare_problema_entry = tk.Entry(info_frame)
   rezolvare_problema_entry.grid(row=3, column=2)

   breakdown_checkbox = tk.Checkbutton(info_frame, text="BREAKDOWN (se bifeaza daca a fost BREAKDOWN)")
   breakdown_checkbox.grid(row=4, column=1)

# ARANJAMENTUL PE APLICATIE

   for widget in info_frame.winfo_children():
   widget.grid_configure(padx=10, pady=10)

# Goleste input-urile dupa ce s a trimis raportul

   descriere_problema_entry.delete(0, tk.END)
   durata_interventie_entry.delete(0, tk.END)
   rezolvare_problema_entry.delete(0, tk.END)

# BUTOANELE

   buton_trimitere = tkinter.Button(info_frame, text="Trimitere", fg="blue", command=trimitere_date)
   buton_trimitere.grid(row=5, column=1, sticky="news")

   buton_iesire = tkinter.Button(info_frame, fg="red", text="Iesire", command=root.quit)
   buton_iesire.grid(row=6, column=1, sticky="news")

# AFISAREA APLICATIEI

   root.mainloop()

ERROR:

C:\Users\sucimi2\Desktop\pythonProject3\Scripts\python.exe           C:\Users\sucimi2\PycharmProjects\pythonProject3\main.py

Traceback (most recent call last):

File "C:\Users\sucimi2\PycharmProjects\pythonProject3\main.py", line 61, in <module>

data_insert_tuple = (nume_tehnician, schimb, linia,

NameError: name 'nume_tehnician' is not defined

 

Process finished with exit code 1

Hello, I’m trying to make an app that retrieve infos and bring them to a data base, everything seems fine ( the GUI works, the data base is created and accessible ), but I’m getting the error I mentioned before (and I guess that will be the case for everyting from data_insert_tuple, not only that particularly one)

Does anybody know why this happen? I saw a tutorial on Youtube and for her, it worked without any further complications.

2
  • 2
    Please fix the indentation in your post. We can't tell which lines are inside the trimitere_date function. nume_tehnician is a local variable in the function, you can't use it outside the function. Commented Jul 27, 2023 at 7:50
  • Please fix the indentation, the code is unreadable. But given that nume_tehnician= line is first after def, I'm gonna say it's actually in the function and the line that breaks is not - please learn about scopes (nume_tehnician is a local variable to the function it is, it doesn't exist outside of it) Commented Jul 27, 2023 at 7:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.