Show HN: Python GUI with tkinter and a Markdown-type language for describing it
v1, lots of code and redundancy
def main():
global user_info_text
root = tk.Tk()
root.title("Okta")
main_frame = ttk.Frame(root)
main_frame.grid(row=0, sticky='w', padx=10, pady=10)
ttk.Label(main_frame, text="Okta URL:").grid(row=0, sticky='w')
url_entry = ttk.Entry(main_frame, width=40)
url_entry.insert(0, okta_url)
url_entry.grid(row=1, sticky='w')
ttk.Label(main_frame, text="Username:").grid(row=2, sticky='w')
username_entry = ttk.Entry(main_frame, width=40)
username_entry.insert(0, username)
username_entry.grid(row=3, sticky='w')
ttk.Label(main_frame, text="Password:").grid(row=4, sticky='w')
password_entry = ttk.Entry(main_frame, show="*", width=40)
password_entry.grid(row=5, sticky='w')
command = lambda _=None: sign_in(url_entry.get(), username_entry.get(), password_entry.get())
password_entry.bind("<Return>", command)
password_entry.focus()
ttk.Button(main_frame, text="Sign In", command=command).grid(row=6, sticky='w')
ttk.Label(main_frame, text="User Info:").grid(row=7, sticky='w')
user_info_text = ScrolledText(main_frame, wrap=tk.WORD, width=100, height=30)
user_info_text.grid(row=8, sticky='w')
root.mainloop()
v2, refactor and invent a markdown-type language for the GUI: Label
_Entry_
_*_ (Password Entry)
[Button]
|ScrolledText|
Does something like this already exist?code:
def main():
global user_info_text
root, url_entry, username_entry, password_entry, sign_in_button, user_info_text = gui(f"""
Okta URL
_{okta_url}_
Username
_{username}_
Password
_*_
[Sign In]
User Info
|text|
""")
command = lambda _=None: sign_in(url_entry.get(), username_entry.get(), password_entry.get())
sign_in_button['command'] = command
password_entry.bind("<Return>", command)
password_entry.focus()
root.mainloop()
def gui(s):
root = tk.Tk()
root.title("Okta")
main_frame = ttk.Frame(root)
main_frame.grid(row=0, sticky='w', padx=10, pady=10)
ws = [root]
for row, w in enumerate(w.strip() for w in s.split('\n') if w.strip()):
text = w[1:-1]
if w.startswith('_'):
show, text = (text, '') if text == '*' else ('', text)
w = ttk.Entry(main_frame, width=40, show=show)
w.insert(0, text)
elif w.startswith('['):
w = ttk.Button(main_frame, text=text)
elif w.startswith('|'):
w = ScrolledText(main_frame, wrap=tk.WORD, width=100, height=30)
else:
w = ttk.Label(main_frame, text=w + ':')
w.grid(row=row, sticky='w')
if not isinstance(w, ttk.Label): ws.append(w)
return ws
0 comments
[ 3.9 ms ] story [ 8.2 ms ] threadNo comments yet.