0

I have an error in my program: "Taula_G3110 () NameError: name 'Taula_G3110' is not defined"

My question is: I want to call a function that is inside an IF loop.This function is in another file. I have tried everything with imports: "from Kleben_Tabelle import Taula_G3110, Taula_G3111. import Kleben_Tabelle ", but there is no way.

Does anyone have an idea what I'm doing wrong?

Code:

from tkinter import *
from PIL import Image, ImageTk
from tkinter import ttk
from tkinter import messagebox
#from Kleben_Tabelle import *
import serial
import time
import PIL.Image
import Kleben_Tabelle


root = Tk()
root.geometry("1000x600")
# root.resizable (False,False)
root.title("Combobox")

arduino = serial.Serial("COM7", 9600)
time.sleep(0.1)  # reducir el uso de la CPU.Prueba con diferentes valores (0.01 a 0.1)


def cambiar():
    mes = combo.get()
    if mes == "G3110":
        label_resultat.configure(text=txt)
        Taula_G3110()

    if mes == "G3111":
        label_resultat.configure(text=txt2)
        Taula_G3111()
    if mes == "G3112":
        messagebox.showinfo("Mes", "Marzo")

def apagarLED():
    arduino.write(b'4')
    time.sleep(1)


def cerrarInterfaz():
    # cerrar comunicación Serial
    global raiz
    arduino.close()
    # cerrar ventana
    root.destroy()

image = Image.open ('Edifici_Knauer_blau.png')
photo_image = ImageTk.PhotoImage(image)
label = Label(root, image=photo_image)
label.pack()

frame_resultat = Frame(root, width=400, height=100, relief="flat", highlightbackground="blue", highlightthickness=1)
frame_resultat.place(x=250, y=200)

label_resultat = Label(root, text="", bg="yellow", borderwidth=0, relief="groove", width=20, height=2, justify='left',
                       highlightbackground="blue", highlightthickness=1)
label_resultat.place(x=80, y=200)

etiqueta = Label(root, text="Zelle: Kleben")
etiqueta.place(x=100, y=40)

combo = ttk.Combobox(root, state="readonly")
combo.place(x=100, y=70)
combo["values"] = ("G3110", "G3111", "G3112", "1")
combo.current(0)

boton = Button(root, text="Cambiar mes", command=cambiar)
boton.place(x=100, y=100)

# boton de apagado del LED
btnApagar = ttk.Button(root, text="Reset", command=apagarLED)
# btnApagar = ttk.Button(raiz,text ="Reset",command = clearTextInput)
btnApagar.place(x=420, y=450)
# boton de Cerrar interfaz
btnCerrar = ttk.Button(root, text="Cerrar", command=cerrarInterfaz)
btnCerrar.place(x=420, y=480)

txt = ("G3110 Frontabdeckung")
txt2 = ("G3111 Frontabdeckung")

root.mainloop()

and this ist my other File with this Module-Function:(File: Kleben_Tabelle.py)

def Taula_G3110():
    arduino.write(bytes(b'T'))
    arbol = ttk.Treeview(frame_resultat,columns=("Bauteile","Regal","Lager"))
    arbol.column ('#0',width=100)
    arbol.column ('Bauteile',width=100)
    arbol.column ('Regal',width=80)
    arbol.column ('Lager',width=80)
    arbol.insert("",END,text="G3110",values=("P6400","K2.0001.01","Regal 2"))
    arbol.insert("",END,text="G3110",values=("P6406XA","K1.0004.01"))
    arbol.insert("",END,text="G3110",values=("P6403XA","K1.0003.01"))
    arbol.heading("#0",text="Model")
    arbol.heading("Bauteile",text="Bauteile")
    arbol.heading("Regal",text="Regal")
    arbol.place(x=100,y=70)
    arbol.pack()
7
  • 1
    you're probably best off posting the actual code, and adding a tag for the programming language you're using. May I suggest: stackoverflow.com/help/how-to-ask Commented Jan 23, 2022 at 11:26
  • Your import looks correct, assuming it is a function in that module. Maybe post the exception stack trace from the import statement? What do you mean "inside an if statement"? If you can post code to recreate the error here, we can certainly help. Commented Jan 23, 2022 at 22:28
  • Thanks Kenn Ostrom Commented Jan 24, 2022 at 16:45
  • In the example above, you should be using Kleben_Tabelle.Taula_G3110() when calling the function. I assume you've tried that though. Other than that - we need to know the disk layout of your project and possibly your PYTHONPATH value. We also need to see the code in the Kleben_Tabelle module. Commented Jan 24, 2022 at 16:50
  • I call the function as you told me...no error but now I get this error: arduino.write(bytes(b'T')) NameError: name 'arduino' is not defined Commented Jan 24, 2022 at 17:00

1 Answer 1

0

In order to call a function in a module that you've imported, you need to reference the module and function like so:

import Kleben_Tabelle

...

def cambiar():
    mes = combo.get()
    if mes == "G3110":
        label_resultat.configure(text=txt)
        Kleben_Tabelle.Taula_G3110()
Sign up to request clarification or add additional context in comments.

3 Comments

the import of the module, I have also made it The import of the Serial library for arduino also: import serial But I still have the error: arduino.write(bytes(b'T')) NameError: name 'arduino' is not defined
Hi @KamaeBerlin that sounds like a different question to this. Please either update this question with the other module's contents to show us what you're doing or else post a new question with all that information in and we can help with that question. Unfortunately there's never enough information in a comment to be able to hazard a guess at a solution.
I have asked another question. I hope this makes it clearer. Thank you very much anyway.:stackoverflow.com/questions/70867361/…

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.