So I'm trying to create some sort of email log system with the subject and message previewed on each line, like gmail.
In mainWindowScript.py
, I have a 'compose' button that appends a string to an array in getLogs.py
, and a 'logs' button that runs getLogs.py
using the os module. In getLogs.py
, I just have a ListBox
. I used tkinter to create buttons and listboxes
.
When I run mainWindowScript.py
, it first opens the listbox
created in getLogs.py
which isn't supposed to happen. But the weird part is when I close that window and click my 'compose' button, the list I tried to append to is still empty, making the listbox
empty.
It's really confusing I need help.
Here is mainWindowScript.py
:
import tkinter as tk
from tkinter import ttk
import os
import getLogs as gl
mainWin = tk.Tk()
canvas = tk.Canvas(mainWin, width = 400, height = 400)
canvas.pack()
frame = tk.Frame(mainWin, bg = "gray")
frame.place(relx = 0, rely = 0, relwidth = 1, relheight = 1)
def compose():
gl.tos.append("isybgf")
#os.system("python email_gui.py") #run another python file
def getEmailLogs():
os.system("python getLogs.py")
composeButton = tk.Button(frame, bg = "blue", fg = "white", text = "COMPOSE", command = compose)
composeButton.place(relx = 0.3, rely = 0.2, relwidth = 0.4, relheight = 0.2)
logsButton = tk.Button(frame, bg = "blue", fg = "white", text = "LOGS", command = getEmailLogs)
logsButton.place(relx = 0.3, rely = 0.5, relwidth = 0.4, relheight = 0.2)
mainWin.mainloop()
And getLogs.py
:
import tkinter as tk
mainWind = tk.Tk()
canvas = tk.Canvas(mainWind, width = 400, height = 600)
canvas.pack()
frame = tk.Frame(mainWind, bg = "gray")
frame.place(relx = 0, rely = 0, relwidth = 1, relheight = 1)
mailLogs = tk.Listbox(frame)
mailLogs.place(relx = 0.1, rely = 0.05, relwidth = 0.8, relheight = 0.9)
tos = []
subjects = []
messages = []
print(tos)
mails = {
"to:": tos,
"subject:": subjects,
"message:": messages
}
for i in range(0, len(tos)):
emailLogTitle = "{}: {} - {}".format(mails["to:"][i], mails["subject:"][i], mails["message:"][i])
mailLogs.insert('end', emailLogTitle)
mainWind.mainloop()