我有一个程序可以读取和显示Outlook电子邮件的主题行。如果关键字" up"我希望它以绿色显示主题。是在主题。红色如果" down"是在主题。此外,当我使用if,elif,else语句时,程序似乎不起作用。我想使用它,因为我希望程序显示红色为"向下",绿色用于"向上",黑色/白色用于任何其他主题。
它使用我的代码,但每次阅读/显示新的电子邮件主题时,我都无法弄清楚如何清除和刷新标签。
我已经尝试过destory()和os.system(' cls')而没有运气。
示例:
messages = inbox.Items
message = messages.GetLast()
body_content = message.Subject
if ' up ' in body_content:
self.answer_label['text'] = os.system('cls')
self.answer_label['text'] = (body_content)
else:
self.answer_label2['text'] = os.system('cls')
self.answer_label2['text'] = (body_content)
self.master.after(20, self.timer)
这是我原来的所有代码:
import win32com.client
import os
import tkinter
from tkinter import Tk, Label, Button
class myGUI:
def timer(self):
import pythoncom
pythoncom.CoInitialize()
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
body_content = message.Subject
if ' up ' in body_content:
self.answer_label['text'] = (body_content)
else:
self.answer_label2['text'] = (body_content)
self.master.after(20, self.timer)
def __init__(self, master):
self.master = master
master.title("CheckStat")
self.answer_label = Label(master, text='', fg="light green", bg="dark green", font="Helvetica 64 bold italic")
self.answer_label.grid(column=0, row=0)
self.answer_label2 = Label(master, text='', fg="red", bg="dark red", font="Helvetica 64 bold italic")
self.answer_label2.grid(column=0, row=0)
self.timer()
root = Tk()
my_gui = myGUI(root)
root.mainloop()
当我使用" if,elif,else"时,程序似乎没有使用正确的颜色更新。下面。有什么想法吗?
import win32com.client
import os
import tkinter
from tkinter import Tk, Label, Button
class myGUI:
def timer(self):
import pythoncom
pythoncom.CoInitialize()
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
body_content = message.Subject
if ' up ' in body_content:
self.answer_labelUp['text'] = (body_content)
elif ' down ' in body_content:
self.answer_labelDown['text'] = (body_content)
else:
self.answer_labelElse['text'] = (body_content)
self.master.after(20, self.timer)
def __init__(self, master):
self.master = master
master.title("CheckStat")
self.answer_labelUp = Label(master, text='', fg="light green", bg="dark green", font="Helvetica 64 bold italic")
self.answer_labelUp.grid(column=0, row=0)
self.answer_labelDown = Label(master, text='', fg="red", bg="dark red", font="Helvetica 64 bold italic")
self.answer_labelDown.grid(column=0, row=0)
self.answer_labelElse = Label(master, text='', fg="black", bg="white", font="Helvetica 64 bold italic")
self.answer_labelElse.grid(column=0, row=0)
self.timer()
root = Tk()
my_gui = myGUI(root)
root.mainloop()