Python导入脚本不工作(错误:找不到模块)

2024-05-06 13:23:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的第二个脚本中使用变量,但当我尝试导入它时,会出现以下错误:

ModuleNotFoundError: No module named 'register_intervention'

这是我的代码,顺便说一句:

from register_intervention import *

他们在同一个目录上。我需要做什么

主菜单脚本(变量名称为西班牙语,很抱歉):

from tkinter import *
import datetime
from tkinter import ttk
from tkinter import messagebox
from PIL import Image, ImageTk
from pprint import pprint
import pyodbc
import ibm_db
import os

os.chdir('G:\\09 SCRIPTS AUTOMATIZACION\\TICKETING INGENIERIA')

from registro_intervencion import *

def abrir_form_intervencion():
    window.destroy()
    exec(open('G:\\09 SCRIPTS AUTOMATIZACION\\TICKETING INGENIERIA\\registro_intervencion.py').read())

window=Tk()
window.title('Seguimiento')
window.geometry("640x480")
#window.iconbitmap('G:/09 SCRIPTS AUTOMATIZACIÓN/TICKETING INGENIERIA/img/logo-flos.ico')
titulo = Label(text="Base de Datos de Seguimiento", font=("Arial", 16, 'bold'), fg="White", bg="Blue")
titulo.pack()

registro_intervencion = Button(window, text="Registro Intervencion", font=("Arial", 12), command=abrir_form_intervencion)
registro_intervencion.place(relx=.5, rely=.2, anchor="center")

Secodn脚本:

from tkinter import *
import datetime
from tkinter import ttk
from tkinter import messagebox
from pprint import pprint
import pyodbc
import ibm_db

# Opciones de ventana.
window=Tk()
window.title('Seguimiento')
window.geometry("1200x628")
titulo = Label(text="Base de Datos de Seguimiento", font=("Arial", 16, 'bold'), fg="White", bg="Blue")
titulo.pack()

# Conexión con la base de datos AS/400.
conn_db2 = pyodbc.connect('DSN=AS400; UID=ADMIN; PWD=ADMIN')

# Recoger datos de la tabla CENTRO.
centro_cursor = conn_db2.cursor()
resultado_centro = []
buscar_centro = "SELECT centro FROM BIUMO220.TICKCENTRO"
centro_cursor.execute(buscar_centro)
for loop_centro in centro_cursor:
    resultado_centro.append(loop_centro[0])

# Recoger datos de la coleccion INTERVENCION.
intervencion_cursor = conn_db2.cursor()
resultado_intervencion = []
buscar_intervencion = "SELECT tipo_intervencion FROM BIUMO220.TICKINTERVENCION"
intervencion_cursor.execute(buscar_intervencion)
for loop_intervencion in intervencion_cursor:
    resultado_intervencion.append(loop_intervencion[0])

resultado_intervencion = list(dict.fromkeys(resultado_intervencion))  # Disctinct.

# Variables del formulario.
responsable = StringVar()
fecha = IntVar()
centro = StringVar()
tipo_intervencion = StringVar()
subtipo_intervencion = StringVar()
comentario = StringVar()
ref_producto_final = StringVar()
descripcion_producto_final = StringVar()
ref_componente = StringVar()
util = StringVar()
tiempo_aprox_intervencion = StringVar()

# Definir funciones.
# Seleccionar subtipo.
def seleccionar_subtipo(e):
    subtipo_intervencion_cursor = conn_db2.cursor()
    global resultado_subtipo_intervencion
    resultado_subtipo_intervencion = []
    seleccion_intervencion = tipo_intervencion_desplegable.get()
    buscar_subtipo = "SELECT subtipo FROM BIUMO220.TICKINTERVENCION WHERE tipo_intervencion = ?"
    subtipo_intervencion_cursor.execute(buscar_subtipo, seleccion_intervencion)
    for loop_subtipo_intervencion in subtipo_intervencion_cursor:
        resultado_subtipo_intervencion.append(loop_subtipo_intervencion[0])
    subtipo_intervencion_desplegable.config(value=(resultado_subtipo_intervencion))


# Autocompletar la descripcion y la familia
def producto_final_descripcion_familia(i):
    cur = conn_db2.cursor()
    ref = referencia_producto_final_entrada.get()
    res = []
    sql = "SELECT E.TEBEZ1, E.TEBEZ2, A.TXTXB1 FROM BIDBD220.TEIL E, BIDBD220.TABDS A WHERE E.TETENR = ? AND A.TXTXRT = 'TL' AND E.TEPRKL = LTRIM(A.TXTXNR)  AND A.TXSPCD = 'S'"
    cur.execute(sql, ref)
    row = cur.fetchall()
    for rows in row:
        res.append(rows)
    descripcion_producto_final_entrada1.config(text=res)


def componente_descripcion_familia(j):
    componente_cursor = conn_db2.cursor()
    referencia_componente = referencia_componente_entrada.get()
    componente_query = "SELECT E.TEBEZ1, E.TEBEZ2, A.TXTXB1 FROM BIDBD220.TEIL E, BIDBD220.TABDS A WHERE E.TETENR = ? AND A.TXTXRT = 'TL' AND E.TEPRKL = LTRIM(A.TXTXNR)  AND A.TXSPCD = 'S'"
    componente_cursor.execute(componente_query, referencia_componente)
    componente_row = componente_cursor.fetchall()
    descripcion_componente_entrada.config(text=componente_row)


def util_descripcion_familia(k):
    util_cursor = conn_db2.cursor()
    referencia_util = util_entrada.get()
    util_query = "SELECT TRIM(E.TEBEZ1), TRIM(E.TEBEZ2), TRIM(A.TXTXB1) FROM BIDBD220.TEIL E, BIDBD220.TABDS A WHERE E.TETENR = ? AND A.TXTXRT = 'TL' AND E.TEPRKL = LTRIM(A.TXTXNR)  AND A.TXSPCD = 'S'"
    util_cursor.execute(util_query, referencia_util)
    util_row = util_cursor.fetchall()
    descripcion_util_entrada.config(text=util_row)


# Formulario.
# Primera línea. PENDIENTE: Identificador de ticket automatico. | Consulta más alto + 1
responsable_etiqueta = Label(text="Responsable:", font=("Arial", 12))
responsable_etiqueta.place(x=20, y=50)
responsable_entrada = Entry(textvariable=responsable, width="50", font=("Arial", 12))
responsable_entrada.place(x=120, y=50)

fecha_etiqueta = Label(text=f"Fecha: {datetime.date.today(): %d %m %Y}", font=("Arial", 12))
fecha_etiqueta.place(x=600, y=50)

centro_etiqueta = Label(text="Centro:", font=("Arial", 12))
centro_etiqueta.place(x=800, y=50)
centro_desplegable = ttk.Combobox(window, value=resultado_centro, font=("Arial", 12))
centro_desplegable.place(x=860, y=50)

tipo_intervencion_etiqueta = Label(text="Tipo de Intervencion:", font=("Arial", 12))
tipo_intervencion_etiqueta.place(x=20, y=100)
tipo_intervencion_desplegable = ttk.Combobox(window, value=resultado_intervencion, font=("Arial", 12))
tipo_intervencion_desplegable.place(x=170, y=100)

tipo_intervencion_desplegable.bind("<<ComboboxSelected>>", seleccionar_subtipo)

subtipo_intervencion_etiqueta = Label(text="Subtipo:", font=("Arial", 12))
subtipo_intervencion_etiqueta.place(x=400, y=100)
subtipo_intervencion_desplegable = ttk.Combobox(window, value=[" "], font=("Arial", 12))
subtipo_intervencion_desplegable.place(x=470, y=100)

comentario_etiqueta = Label(text="Comentario:", font=("Arial", 12))
comentario_etiqueta.place(x=700, y=100)
comentatio_entrada = Entry(textvariable=comentario, width="40", font=("Arial", 12))
comentatio_entrada.place(x=800, y=100)

referencia_producto_final_etiqueta = Label(text="Ref. Producto Final:", font=("Arial", 12))
referencia_producto_final_etiqueta.place(x=20, y=150)
referencia_producto_final_entrada = Entry(textvariable=ref_producto_final, width="15", font=("Arial", 12))
referencia_producto_final_entrada.place(x=170, y=150)

referencia_producto_final_entrada.bind('<Return>', producto_final_descripcion_familia)

descripcion_producto_final_entrada1 = Label(font=("Arial", 12))
descripcion_producto_final_entrada1.place(x=320, y=150)

descripcion_producto_final_entrada2 = Label(font=("Arial", 12))
descripcion_producto_final_entrada2.place(x=520, y=150)

referencia_componente_etiqueta = Label(text="Ref. Componente:", font=("Arial", 12))
referencia_componente_etiqueta.place(x=20, y=200)
referencia_componente_entrada = Entry(textvariable=ref_componente, width="15", font=("Arial", 12))
referencia_componente_entrada.place(x=160, y=200)

referencia_componente_entrada.bind('<Return>', componente_descripcion_familia)

descripcion_componente_entrada = Label(font=("Arial", 12))
descripcion_componente_entrada.place(x=300, y=200)

util_etiqueta = Label(text="Util:", font=("Arial", 12))
util_etiqueta.place(x=20, y=250)
util_entrada = Entry(textvariable=util, width="15", font=("Arial", 12))
util_entrada.place(x=60, y=250)

util_entrada.bind('<Return>', util_descripcion_familia)

descripcion_util_entrada = Label(font=("Arial", 12))
descripcion_util_entrada.place(x=200, y=250)

tiempo_aprox_intervencion_etiqueta = Label(text="Tiempo Aprox. Intervencion:", font=("Arial", 12))
tiempo_aprox_intervencion_etiqueta.place(x=20, y=300)
tiempo_aprox_intervencion_entrada = Entry(textvariable=tiempo_aprox_intervencion, width="15", font=("Arial", 12))
tiempo_aprox_intervencion_entrada.place(x=220, y=300)

window.mainloop()

选择同一目录时出错:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\py_install\py_394\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "<string>", line 63, in seleccionar_subtipo
  File "C:\py_install\py_394\lib\tkinter\__init__.py", line 3043, in get
    return self.tk.call(self._w, 'get')
_tkinter.TclError: invalid command name ".!combobox2"

Tags: textimportutilplacecursorlabelfontcentro