data.py
class Visitor:
def __init__(self, name, email, ordered_data):
self.name = name
self.email = email
self.ordered_data = ordered_data
visitors = [
Visitor("Bradley Cooper", "BradleyCooper@gmail.com", "not ordered"),
Visitor("Brad Pitt", "BradPitt@gmail.com", "not ordered"),
Visitor("Leonardo DiCaprio", "LeonardoDiCaprio@gmail.com", "not ordered"),
Visitor("Jennifer Connelly", "JenniferConnelly@gmail.com", "not ordered"),
Visitor("Jim Carrey", "JimCarrey@gmail.com", "not ordered")
]
UI.py
from data import visitors
import tkinter
from tkinter.font import Font
from tkinter import ttk
current_visitor = ""
visitors_names = []
i = 0
while (i < len(visitors)):
visitors_names.append(visitors[i].name)
i += 1
def selected(event):
global current_visitor, visitor_info
i = 0
while (i < len(visitors)):
if (visitors_list.get() == visitors[i].name):
current_visitor = visitors[i]
i += 1
visitor_info.configure(state="normal")
visitor_info.delete(1.0,tkinter.END)
visitor_info.insert(tkinter.END, "Name: " + current_visitor.name)
visitor_info.insert(tkinter.END, "\nEmail: " + current_visitor.email)
visitor_info.insert(tkinter.END, "\nOrdered data: " + current_visitor.ordered_data)
visitor_info.configure(state="disabled")
def order():
global current_visitor
current_visitor.ordered_data = set_data_field.get()
root = tkinter.Tk()
title_font = Font(family="Consolas", size=16)
main_font = Font(family="Consolas", size=12)
root.resizable(False, False)
root.title("GUI")
root.geometry("640x360")
title = tkinter.Label(root, text="2020 Summer Olympics")
title.configure(font=title_font)
title.place(x=200, y=0)
opening_data = tkinter.Label(root, text="Opening: 24 July")
clothing_data = tkinter.Label(root, text="Closing: 9 August")
opening_data.configure(font=main_font)
clothing_data.configure(font=main_font)
opening_data.place(x=130, y=30)
clothing_data.place(x=350, y=30)
v = tkinter.Label(root, text="Visitor:")
v.configure(font=main_font)
v.place(x=170, y=80)
visitors_list = ttk.Combobox(root, values=visitors_names)
visitors_list.current(0)
visitors_list.bind("<<ComboboxSelected>>", selected)
visitors_list.configure(font=main_font)
visitors_list.place(x=270, y=80)
visitor_info = tkinter.Text(root, height = 5, width = 40)
visitor_info.configure(font=main_font, state="disabled")
visitor_info.place(x=140, y=120)
d = tkinter.Label(root, text="Order:")
d.configure(font=main_font)
d.place(x=120, y=250)
set_data_field = tkinter.Entry(root)
set_data_field.configure(font=main_font)
set_data_field.place(x=225, y=250)
set_data_field.insert(0, "24 July")
make_order = tkinter.Button(root, text="Make order", command=order)
make_order.configure(font=main_font)
make_order.place(x=460, y=245)
root.mainloop()
Comments
Leave a comment