Skip to content
Snippets Groups Projects
Verified Commit 6a7c4307 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Start work on client, implement main frame

parent f9241dc7
No related branches found
No related tags found
No related merge requests found
import json import json, requests
from tkinter import messagebox, ttk from tkinter import messagebox, ttk
from tkinter import * from tkinter import *
...@@ -6,28 +6,63 @@ from tkinter import * ...@@ -6,28 +6,63 @@ from tkinter import *
root = Tk() root = Tk()
## Global Variables ## Global Variables
name = StringVar() connect_url = StringVar()
age = StringVar()
## Subroutines ## Subroutines
def get_endpoint(endpoint):
return connect_url.get() + endpoint
def submit(*args): def submit(*args):
messagebox.showinfo("Not implemented") messagebox.showinfo("Not implemented", "Not just yet...")
def connect(*args):
try:
res = requests.get(get_endpoint("/"))
if res.status_code == 200:
# Success
# TODO check for valid JSON response, possibly change to /status endpoint
messagebox.showinfo("OK!", "Successfully connected")
connect_status_label.configure(text="Connected")
# TODO focus on other tab
else:
# Failure
# TODO failure message
pass
except:
# Failure
# TODO failure message
pass
## Main program code ## Main program code
root.title("Pizza Palace") root.title("Pizza Palace")
tab_control = ttk.Notebook(root)
connect_frame = ttk.Frame(tab_control, padding="3 3 12 12")
connect_frame.grid(column=0, row=0, sticky=(N, W, E, S))
connect_frame.columnconfigure(0, weight=1)
connect_frame.rowconfigure(0, weight=1)
mainframe = ttk.Frame(root, padding="3 3 12 12") connect_url_label = ttk.Label(connect_frame, text="Server URL:")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) connect_url_field = ttk.Entry(connect_frame, width=20, textvariable=connect_url)
root.columnconfigure(0, weight=1) connect_url_label.grid(column=1, row=1, sticky=(W, E))
root.rowconfigure(0, weight=1) connect_url_field.grid(column=2, row=1, sticky=(W, E))
connect_url.set("http://localhost:5000")
submit_button = ttk.Button(mainframe, text="Go!", command=submit) connect_status_label = ttk.Label(connect_frame, text="Not connected")
submit_button.grid(column=2, row=3, sticky=(W, E)) connect_status_label.grid(column=1, row=2, sticky=(W, E))
for child in mainframe.winfo_children(): connect_submit_button = ttk.Button(connect_frame, text="Go!", command=connect)
connect_submit_button.grid(column=1, row=3, sticky=(W, E))
for child in connect_frame.winfo_children():
child.grid_configure(padx=5, pady=5) child.grid_configure(padx=5, pady=5)
submit_button.focus() connect_submit_button.focus()
root.bind("<Return>", submit) connect_frame.bind("<Return>", submit)
# TODO other tabs
tab_control.add(connect_frame, text="Connect")
tab_control.pack(expand=1, fill="both")
root.mainloop() root.mainloop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment