Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import smtplib
- TITLE_FONT = ("Helvetica", 18, "bold")
- class SampleApp(tk.Tk):
- def __init__(self):
- tk.Tk.__init__(self)
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {}
- for F in (StartPage, PageOne, PageTwo):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame(StartPage)
- def show_frame(self, c):
- frame = self.frames[c]
- frame.tkraise()
- class StartPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text="PyMail",foreground = "Red", font=("Courier", 30, "bold"))
- label.pack(side="top")
- sublabel = tk.Label(self, text="Bringing you then the easiest way of communication",
- font=("Courier", 15))
- sublabel.pack()
- wallpaper = tk.PhotoImage(file='Python-logo-notext.gif')
- img = tk.Label(self, image=wallpaper)
- img.image = wallpaper
- img.pack(side="top", expand = True)
- button1 = tk.Button(self, text="Click Here to Login to your account",fg="red",
- command=lambda: controller.show_frame(PageOne))
- button2 = tk.Button(self, text="Go to Page Two",
- command=lambda: controller.show_frame(PageTwo))
- button2.pack(side="bottom")
- button1.pack(side="bottom")
- class PageOne(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller=controller
- label = tk.Label(self, text="Personal Information", font=TITLE_FONT, foreground="blue")
- label.pack(side="top", fill="x", pady=10)
- global optionv
- self.optionv = tk.StringVar()
- self.optionv.set("---Select One---")
- optionm = tk.OptionMenu(self, self.optionv, "---Select One---", "@gmail.com", "@yahoo.com", "@hotmail.com")
- t1 = tk.Label(self, text="Email Account: ")
- self.v = tk.StringVar()
- self.v.set("")
- entry1 = tk.Entry(self, textvariable=self.v)
- t2 = tk.Label(self,text="nPassword: ")
- self.pwd = tk.StringVar()
- self.pwd.set("")
- entry2 = tk.Entry(self, textvariable=self.pwd)
- entry2.config(show="*")
- lgbutton=tk.Button(self, text="Log In", command=self.login)
- button = tk.Button(self, text="Go to the start page",
- command=lambda: controller.show_frame(StartPage))
- #final = tk.Label(self, textvariable=self.v)
- #finalpwd = tk.Label(self, textvariable=self.pwd)
- t1.pack()
- entry1.pack()
- optionm.pack()
- t2.pack()
- entry2.pack()
- #final.pack()
- #finalpwd.pack()
- lgbutton.pack()
- button.pack(side="bottom")
- def login(self):
- value = tk.Label(self, text="Invalid username / password", font=("Courier", 15, "bold"), foreground="red")
- success = tk.Label(self, text="Login was Successful n (Click ""Continue"" to compose email)", font=("Courier", 15, "bold"), foreground="blue")
- cbutton = tk.Button(self, text="Continue", command=lambda: self.controller.show_frame(PageTwo))
- status = tk.Label(self, text="Please select your email domain", foreground="red")
- if self.optionv.get() == "@gmail.com":
- try:
- global server
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.ehlo()
- server.starttls()
- server.login(self.v.get()+self.optionv.get(), self.pwd.get())
- success.pack()
- cbutton.pack(side="bottom")
- except:
- value.pack()
- elif self.optionv.get() == "@yahoo.com":
- try:
- server = smtplib.SMTP("smtp.yahoo.com", 587)
- server.ehlo()
- server.starttls()
- server.login(self.v.get()+self.optionv.get(), self.pwd.get())
- success.pack()
- cbutton.pack(side="bottom")
- except:
- value.pack()
- elif self.optionv.get() == "@hotmail.com":
- try:
- server = smtplib.SMTP("smtp.live.com", 587)
- server.ehlo()
- server.starttls()
- server.login(self.v.get()+self.optionv.get(), self.pwd.get())
- success.pack()
- cbutton.pack(side="bottom")
- except:
- value.pack()
- else:
- status.pack()
- class PageTwo(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text="Compose Mail", font=TITLE_FONT, foreground="green")
- label.pack(side="top", fill="x", pady=10)
- self.reciever = tk.StringVar()
- self.reciever.set("")
- senderl = tk.Label(self, text="Send to: ")
- rmail = tk.Entry(self, textvariable=self.reciever)
- self.senderoption = tk.StringVar()
- self.senderoption.set("---Select One---")
- senderdomain = tk.OptionMenu(self, self.senderoption, "---Select One---", "@gmail.com", "@hotmail.com", "@yahoo.com")
- self.mail = tk.StringVar()
- self.mail.set("")
- self.textw = tk.Entry(self, textvariable=self.mail)
- button = tk.Button(self, text="Go to the start page",
- command=lambda: controller.show_frame(StartPage))
- sendbutton = tk.Button(self, text = "Send Mail", command=self.sendmail)
- senderl.pack(side="top", anchor="w")
- rmail.pack(side="top", anchor="nw")
- senderdomain.pack(side="top", anchor="nw")
- self.textw.pack(fill="both")
- button.pack(side="bottom")
- sendbutton.pack(side="bottom")
- def sendmail(self):
- sent = tk.Label(self, text="Email has been sent")
- if self.senderoption.get() == "@gmail.com":
- try:
- server.sendmail(self.v.get()+self.optionv.get(), self.reciever.get()+self.senderoption.get(), "YES")
- print("Success")
- sent.pack()
- except:
- print("Unsuccesful")
- print(PageOne.self.v.get())
- if __name__ == "__main__":
- app = SampleApp()
- app.title("PyMail")
- app.geometry("400x400")
- app.mainloop()
- class PageTwo(tk.Frame):
- def __init__(self, parent, controller):
- ...
- self.controller=controller
- ...
- class SampleApp(tk.Tk):
- ...
- def get_page(self, page_class):
- return self.frames[page_class]
- ...
- page1 = self.controller.get_page(PageOne)
- page1.v.set("Hello, world")
- class SampleApp(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- self.shared_data = {
- "username": tk.StringVar(),
- "password": tk.StringVar(),
- ...
- )
- entry1 = tk.Entry(self, textvariable=self.controller.shared_data["username"])
- ...
- username = self.controller.shared_data["username"].get()
- import tkinter as tk
- from tkinter import StringVar
- LARGE_FONT = ("Verdana", 12)
- class Club(tk.Tk):
- def get_page(self, page_class):
- return self.frames[page_class]
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.shared_data = {
- "username": tk.StringVar(),
- "password": tk.StringVar(),
- }
- self.frames = {}
- for F in (Terminal, newUser, newUserSubmitButton, delUser):
- frame = F(container, self)
- self.frames[F] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame(Terminal)
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise()
- class Terminal(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text="Welcome to the club terminal. Click the options below", font=LARGE_FONT)
- label.grid(columnspan=3)
- button = tk.Button(self, text="Visit new User",
- command=lambda: controller.show_frame(newUser))
- button.grid(row=1, column=0)
- button2 = tk.Button(self, text="Visit del User",
- command=lambda: controller.show_frame(delUser))
- button2.grid(row=1, column=1)
- class newUser(tk.Frame):
- def __init__(self, parent, controller):
- def submitButton():
- username = self.controller.shared_data["username"].get()
- print(username)
- newUserSubmitButton(self, parent, controller)
- tk.Frame.__init__(self, parent)
- welcomelabel = tk.Label(self, text="Add New User/s", font=LARGE_FONT)
- welcomelabel.grid(columnspan=2, sticky="ew")
- userNameLabel = tk.Label(self, text="Username")
- userNameLabel.grid(row=1, column=0, sticky="e")
- userNameEntry = tk.Entry(self, textvariable=self.controller.shared_data["username"])
- userNameEntry.grid(row=1, column=1)
- userMemTypeLabel = tk.Label(self, text="Membership Type")
- userMemTypeLabel.grid(row=2, column=0, sticky="e")
- variable = StringVar(self)
- variable.set("Full")
- userMemTypeMenu = tk.OptionMenu(self, variable, "Full", "Half")
- userMemTypeMenu.grid(row=2, column=1)
- userMemYearsLabel = tk.Label(self, text="Years that member is in the club")
- userMemYearsLabel.grid(row=3, column=0, sticky="e")
- userMemYearsEntry = tk.Entry(self)
- userMemYearsEntry.grid(row=3, column=1)
- newusersubmitbutton = tk.Button(self, text="submit", command=submitButton)
- newusersubmitbutton.grid(columnspan=2)
- class newUserSubmitButton(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- # username = newUser.submitButton()
- print(username)
- class delUser(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text="del User!!!", font=LARGE_FONT)
- label.pack(pady=10, padx=10)
- button1 = tk.Button(self, text="Back to Home",
- command=lambda: controller.show_frame(Terminal))
- button1.pack()
- button2 = tk.Button(self, text="new User",
- command=lambda: controller.show_frame(newUser))
- button2.pack()
- app = Club()
- app.title("Club Terminal")
- app.iconbitmap("table.ico")
- app.mainloop()
- class firstClass():
- global my_var_first
- my_var_first = "first variable"
- print(my_var_first) # This will work, because the var is in the global frame
- class secondClass():
- my_var_second = "second variable"
- print(my_var_first) # This will work, as the var is in the global frame and not defined in the class
- print(my_var_second) # This won't work, because there is no my_var_second in the global frame
- x = 5
- def print_variable():
- x = 3
- print(x)
- print(x)
- print_variable()
- # OUTPUT:
- # 5
- # 3
Add Comment
Please, Sign In to add comment