在Python中将我的代码转换为应用程序时出现问题

时间:2018-12-31 13:44:55

标签: python tkinter

我正在尝试构建一个应用程序,该应用程序创建一个GUI,并根据用户在其上写入的数据创建一个合适的Word文档。 (我尝试使用pyinstaller,但失败了) 我有两个问题:

  1. 按按钮完成GUI后,我无法找到打开在屏幕上创建的Word文档的功能。
  2. 更重要的是,我无法将代码转换为应用程序。

    我尝试使用pyinstaller,但是当我运行可执行文件时,它创建的终端给了我这个答案:

Terminal situation: /Users/alessiomonino/Desktop/alimentazione_papa ; exit;
MBP-di-Alessio:~ alessiomonino$ /Users/alessiomonino/Desktop/alimentazione_papa ; exit;
Traceback (most recent call last):
  File "alimentazione_papa.py", line 9, in <module>
  File "site-packages/docx/api.py", line 25, in Document
  File "site-packages/docx/opc/package.py", line 116, in open
  File "site-packages/docx/opc/pkgreader.py", line 32, in from_file
  File "site-packages/docx/opc/phys_pkg.py", line 31, in __new__
docx.opc.exceptions.PackageNotFoundError: Package not found at '/var/folders/0_/lzdcn4pd0dxgmnxp1y108qwh0000gn/T/_MEIBeXKXD/docx/templates/default.docx'
[9950] Failed to execute script alimentazione_papa
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

我的代码

try:
    from Tkinter import *
except ImportError:
    from tkinter import *
from tkinter import messagebox
from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Inches
document = Document()




temperatura='0 a 10°C'

def crea_documento():
    #should insert messagebox for when you select male and female both
    #sesso
    C1Var = CheckVar1.get()
    C2Var = CheckVar2.get()
    if C1Var == 1:
        sesso = 'maschio'
    elif C2Var==1:
        sesso='femmina'
    else:
        sesso= 'niente'

    #predisposti
    C3Var = CheckVar3.get()
    C4Var = CheckVar4.get()
    C5Var = CheckVar5.get()
    if C3Var == 1:
        predisposti = "sono predisposti all'obesità"
    elif C4Var==1:
        predisposti='sono predisposti al dimagrimento'
    elif C5Var==1:
        predisposti='non hanno nessuna predisposizione di razza'
    else:
        predisposti= 'niente'

    #fisico
    C6Var = CheckVar6.get()
    C7Var = CheckVar7.get()
    C8Var = CheckVar8.get()
    if C6Var == 1:
        fisico = "sottopeso"
    elif C7Var==1:
        fisico='normopeso'
    elif C8Var==1:
        fisico='sovrappeso'
    else:
        fisico= 'niente'

    #temperamento
    C9Var = CheckVar9.get()
    C10Var = CheckVar10.get()
    C11Var = CheckVar11.get()
    C12Var = CheckVar12.get()
    C13Var = CheckVar13.get()
    if C9Var == 1:
        temperamento = "tranquillo"
    elif C10Var == 1:
        temperamento = 'moderatamento attivo'
    elif C11Var == 1:
        temperamento = 'normale'
    elif C12Var == 1:
        temperamento = 'nervoso e attivo'
    elif C13Var == 1:
        temperamento = 'nervoso e iperattivo'
    else:
        temperamento = 'niente'

    C14Var = CheckVar14.get()
    C15Var = CheckVar15.get()
    C16Var = CheckVar16.get()
    C17Var = CheckVar17.get()
    if C14Var == 1:
        temperatura = "da -10°C a 0°C"
    elif C15Var == 1:
        temperatura = 'da 0°C a 10°C'
    elif C16Var == 1:
        temperatura = 'da 10°C a 30°C'
    elif C17Var == 1:
        temperatura = 'da 30°C a 35°C'
    else:
        temperatura = 'niente'

    #domande aperte
    animale = Entry.get(E1)
    proprietario = Entry.get(E2)
    razza = Entry.get(E3)
    eta=Entry.get(E4)
    microchip=Entry.get(E5)
    peso=Entry.get(E6)

    EM=int(87)
    quan_giornaliera=int(67)
    aggiunte='tre banane'

    EM=str(EM)
    quan_giornaliera=str(quan_giornaliera)

    #creazione documento
    paragraph1 = document.add_paragraph('Clinica Veterinaria')
    paragraph1.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
    heading1 = document.add_heading('Animal Care srl', level=0)
    heading1.bold = True
    heading1.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
    paragraph2 = document.add_paragraph('Via Maù, 18')
    paragraph2.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
    paragraph3 = document.add_paragraph('33035 Martignacco (UD)')
    paragraph3.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
    run = paragraph3.add_run()
    run.add_break()
    paragraph4 = document.add_paragraph('Informazioni su '+ animale)
    paragraph4.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph5= document.add_paragraph('di proprietà di '+proprietario)
    paragraph5.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph6= document.add_paragraph('di razza: '+razza)
    paragraph6.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph7 = document.add_paragraph('di età: ' + eta)
    paragraph7.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph8= document.add_paragraph('di sesso: '+ sesso)
    paragraph8.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph9= document.add_paragraph('di n.microchip: '+microchip)
    paragraph9.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph10= document.add_paragraph('di peso: '+peso)
    paragraph10.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph11= document.add_paragraph('I '+razza+ ' ' + predisposti)
    paragraph11.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph12= document.add_paragraph(animale +' è '+fisico)
    paragraph12.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph13= document.add_paragraph(animale+' è '+temperamento)
    paragraph13.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph14= document.add_paragraph('temperatura ambiente: '+temperatura)
    paragraph14.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph15 = document.add_paragraph('')
    paragraph15.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph16 = document.add_paragraph('')
    paragraph16.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph17 = document.add_paragraph('Proposta di dieta per '+ animale)
    paragraph17.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph18 = document.add_paragraph('EM totale: ' + EM)
    paragraph18.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph19 = document.add_paragraph('Tipo di mangime: Disugual')
    paragraph19.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph20 = document.add_paragraph('Quantità di mangime giornaliero: '+ quan_giornaliera)
    paragraph20.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    paragraph21 = document.add_paragraph('Eventuali aggiunte: '+ aggiunte)
    paragraph21.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT

    document.save('ji.docx')


#domande aperte
top = Tk()
top.title("CALCOLATORE DIETA")
Label(top, text="Domande aperte:", fg = "green").grid(row=1, column=0)
L1 = Label(top, text="nome cane/gatto",).grid(row=2,column=0)
L2 = Label(top, text="nome e cognome proprietario",).grid(row=3,column=0)
L3 = Label(top, text="razza",).grid(row=4,column=0)
L4 = Label(top, text="età",).grid(row=5,column=0)
L5 = Label(top, text="numero del microchip",).grid(row=6,column=0)
L6 = Label(top, text="peso: ",).grid(row=7,column=0)
E1 = Entry(top, bd =5)
E1.grid(row=2,column=1)
E2 = Entry(top, bd =5)
E2.grid(row=3,column=1)
E3 = Entry(top, bd =5)
E3.grid(row=4,column=1)
E4 = Entry(top, bd =5)
E4.grid(row=5,column=1)
E5 = Entry(top, bd =5)
E5.grid(row=6,column=1)
E6 = Entry(top, bd =5)
E6.grid(row=7,column=1)

Label(top, text="       ").grid(row=1, column=2)

#Sesso del cane/gatto
Label(top, text="Sesso Cane:", fg = "red").grid(row=1, column=3)
CheckVar1 = IntVar()
C1= Checkbutton(top, text="maschio", variable= CheckVar1).grid(row=2, column=3)

CheckVar2 = IntVar()
C2=Checkbutton(top, text="femmina", variable=CheckVar2).grid(row=3, column=3)

Label(top, text=" ").grid(row=4, column=3)

Label(top, text=" ").grid(row=5, column=3)

#Predisposizione dellla razza
Label(top, text="Predisposizione della razza:", fg = "green").grid(row=6, column=3)
CheckVar3 = IntVar()
C3= Checkbutton(top, text="all'obesità                       ", variable= CheckVar3).grid(row=7, column=3)

CheckVar4 = IntVar()
C4=Checkbutton(top, text="al dimagrimento              ", variable=CheckVar4).grid(row=8, column=3)

CheckVar5 = IntVar()
C5= Checkbutton(top, text="nessuna predisposizione", variable= CheckVar5).grid(row=9, column=3)

Label(top, text="     ").grid(row=5, column=4)

#Situazione peso
Label(top, text="Situazione peso:              ", fg = "red").grid(row=1, column=5)
CheckVar6 = IntVar()
C6= Checkbutton(top, text="sottopeso                ", variable= CheckVar6).grid(row=2, column=5)

CheckVar7 = IntVar()
C7=Checkbutton(top, text="normopeso              ", variable=CheckVar7).grid(row=3, column=5)

CheckVar8 = IntVar()
C8= Checkbutton(top, text="sovrappeso              ", variable= CheckVar8).grid(row=4, column=5)

Label(top, text=" ").grid(row=5, column=5)

#temperamento
Label(top, text="Temperamento:                  ", fg = "green").grid(row=6, column=5)
CheckVar9 = IntVar()
C9= Checkbutton(top, text="tranquillo                     ", variable= CheckVar9).grid(row=7, column=5)

CheckVar10 = IntVar()
C10=Checkbutton(top, text="moderatamente attivo ", variable=CheckVar10).grid(row=8, column=5)

CheckVar11 = IntVar()
C11= Checkbutton(top, text="normale                       ", variable= CheckVar11).grid(row=9, column=5)

CheckVar12 = IntVar()
C12=Checkbutton(top, text="nervoso e attivo          ", variable=CheckVar12).grid(row=10, column=5)

CheckVar13 = IntVar()
C13= Checkbutton(top, text="nervoso e iperattivo    ", variable= CheckVar13).grid(row=11, column=5)

#temperatura ambiente
Label(top, text="Temperatura ambiente:", fg = "green").grid(row=1, column=6)
CheckVar14 = IntVar()
C14= Checkbutton(top, text="da -10°C a 0°C", variable= CheckVar14).grid(row=2, column=6)

CheckVar15 = IntVar()
C15=Checkbutton(top, text="da 0°C a 10°C  ", variable=CheckVar15).grid(row=3, column=6)

CheckVar16 = IntVar()
C16= Checkbutton(top, text="da 10°C a 30°C", variable= CheckVar16).grid(row=4, column=6)

CheckVar17 = IntVar()
C17=Checkbutton(top, text="da 30°C a 35°C ", variable=CheckVar17).grid(row=5, column=6)

#crea bottone con spazi
Label(top, text="  ", fg = "green").grid(row=19, column=1)

B=Button(top, text ="Invia", command =crea_documento, width=30, height=10, fg='black', activeforeground='green', highlightbackground='blue').grid(row=20,column=3)

Label(top, text="  ", fg = "green").grid(row=21, column=1)

Label(top, text="  ", fg = "green").grid(row=22, column=6)


top.mainloop()

0 个答案:

没有答案