0

I'm creating a program to create a .txt file, where the executable is, but I have to put some kind of password to protect it. I'm open to new ideas.

I'm creating a .txt with the information that I want to save, I tried to put this .txt in a zip file ( because there is a way to set a password with a library) but I couldn't. I'm open to any kind of idea, can be a .txt or.xlsx

`

import tkinter as tk
import os
from os import path
import shutil
from shutil import make_archive


root = tk.Tk()
root.title("Annulus volume v1.0")

mylabel1 = tk.Label(root, text="Name")
mylabel2 = tk.Label(root, text="Start Pressure in anular")
mylabel3 = tk.Label(root, text="End Pressure in anular")
mylabel4 = tk.Label(root, text="Temp in anular")

mylabel1.grid(row=1, column=1)
mylabel2.grid(row=3, column=1)
mylabel3.grid(row=5, column=1)
mylabel4.grid(row=7, column=1)

mylabel11 = tk.Label(root, text=".")
mylabel21 = tk.Label(root, text="barg")
mylabel31 = tk.Label(root, text="barg")
mylabel41 = tk.Label(root, text="°C")

mylabel11.grid(row=1, column=3)
mylabel21.grid(row=3, column=3)
mylabel31.grid(row=5, column=3)
mylabel41.grid(row=7, column=3)

e1 = tk.Entry(root, width=10)
e1.grid(row=1, column=2)
e2 = tk.Entry(root, width=10)
e2.grid(row=3, column=2)
e3 = tk.Entry(root, width=10)
e3.grid(row=5, column=2)
e4 = tk.Entry(root, width=10)
e4.grid(row=7, column=2)

def volume():

    v = str ((e1.get()))
    pi = float (e2.get())
    pf = float(e3.get())
    t = float (e4.get())


    v1 = float(8.13)
    v2= float (t + 273.15)
    v3 = float (pf-pi)
    v4 =float (v3*100.0)
    anular = float ((v1*v2)/v4)


    if (anular > 45): 
        mylabel5 = tk.Label(root, text="situation: flooded ")
        mylabel5.grid(row=9, column=2)
        mylabel5 = tk.Label(root, text="Valor: " + str(anular)[0:6])
        mylabel5.grid(row=10, column=2)


    else:
        mylabel5 = tk.Label(root, text="situation: dry")
        mylabel5.grid(row=9, column=2)
        mylabel5 = tk.Label(root, text="Valor: " + str(anular)[0:6])

        mylabel5.grid(row=10, column=2) 

    myfile = open(v + ".txt","a")
    myfile.write("Vol: " + str (v) + "\n")
    myfile.write("Start Press: " + str (pi) + "\n")
    myfile.write("End Press: " + str (pf) + "\n")
    myfile.write("Temp: " + str (t) + "\n")
    myfile.close() 


calcbutton = tk.Button(root, text="Calc", command=volume, fg="white", bg="purple")
calcbutton.grid(row=11, column=2)

root.mainloop()

`

  • _"I tried to put this .txt in a zip file [...] but I couldn't"_. A password-protected zip archive sounds like a good approach to me, so let's pursue that. What do you mean by "I couldn't"? What happened when you tried? Did it produce an error message? – Kevin Oct 17 '19 at 14:01
  • I'd think of a combination of the following 2 things: https://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python, https://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto – AnsFourtyTwo Oct 17 '19 at 14:04
  • Hello @Kevin ` myfile = open(v + ".txt","a") myfile.write("Vol: " + str (v) + "\n") myfile.write("Start Press: " + str (pi) + "\n") myfile.write("End Press: " + str (pf) + "\n") myfile.write("Temp: " + str (t) + "\n") myfile.close() with ZipFile("finish.zip","w") as newzip newzip.write(v + ".txt") ` I tried it that way, but it gave an error : File "c:/Users/silvag1/Desktop/dog/test.py", line 82 with ZipFile("finish.zip","w") as newzip ^ SyntaxError: invalid syntax – Gabriel Danilo Oct 17 '19 at 14:19
  • It's hard to say if this is the only problem, since code written in comments is hard to analyze, but for starters your `with` statement needs to end with a colon. – Kevin Oct 17 '19 at 14:23

0 Answers0