Skip to content

Instantly share code, notes, and snippets.

@rupython
Created February 25, 2019 10:41
Show Gist options
  • Select an option

  • Save rupython/09c82d2861ac8257947d37bf080f89e6 to your computer and use it in GitHub Desktop.

Select an option

Save rupython/09c82d2861ac8257947d37bf080f89e6 to your computer and use it in GitHub Desktop.
From: Zart
import tkinter as tk, tkinter.ttk as ttk # python 3 stdlib
import tkcalendar as tkc # pip install tkcalendar
def main():
# tk
root = tk.Tk()
root.resizable(False, False)
root.title('Изменение тарифного плана')
style = ttk.Style()
style.theme_use('winnative')
sudo = tk.BooleanVar()
ep = tk.BooleanVar()
lp = tk.BooleanVar()
cl = tk.StringVar()
def do_update(*args):
c = 'sudo ' if sudo.get() else ''
c += 'netup'
if ice.get():
c += ' -uid %s' % ice.get()
if iae.get():
c += ' -aid %s' % iae.get()
if cpe.get():
c += ' -tp_c %s' % cpe.get()
if npe.get():
c += ' -tp_n %s' % npe.get()
if cde.get():
c += ' -today %d' % cde.get_date().toordinal()
if lp.get() and ple.get():
c += ' -tp_link %s' % ple.get()
if ep.get():
c += ' -enterprise'
cl.set(c)
def do_copy(*args):
root.clipboard_clear()
root.clipboard_append(cl.get())
# frame and widgets
frm = ttk.Frame(root, relief='flat')
frm.grid(padx=10, pady=10)
icl = ttk.Label(frm, text='ID клиента')
ice = ttk.Entry(frm)
ial = ttk.Label(frm, text='ID аккаунта')
iae = ttk.Entry(frm)
cpl = ttk.Label(frm, text='Текущий тариф')
cpe = ttk.Entry(frm)
npl = ttk.Label(frm, text='Следующий тариф')
npe = ttk.Entry(frm)
lpc = ttk.Checkbutton(frm, text='Несколько тарифов', variable=lp)
ple = ttk.Entry(frm)
epc = ttk.Checkbutton(frm, text='Юр.лицо', variable=ep)
cdl = ttk.Label(frm, text='Дата смены тарифа')
cde = tkc.DateEntry(frm)
asc = ttk.Checkbutton(frm, text='sudo', variable=sudo)
cmd = tk.Entry(frm, state='readonly', textvariable=cl)
ccb = ttk.Button(frm, text='Копировать', command=do_copy)
nil = ttk.Label(frm, text='ID следующего тарифа')
nie = tk.Entry(frm, state='readonly')
# geometry
pad = 2
icl.grid(row=0, column=0, padx=pad, pady=pad)
ice.grid(row=0, column=1, padx=pad, pady=pad)
cpl.grid(row=0, column=2, padx=pad, pady=pad)
cpe.grid(row=0, column=3, padx=pad, pady=pad)
cdl.grid(row=0, column=4, padx=pad, pady=pad)
ial.grid(row=1, column=0, padx=pad, pady=pad)
iae.grid(row=1, column=1, padx=pad, pady=pad)
npl.grid(row=1, column=2, padx=pad, pady=pad)
npe.grid(row=1, column=3, padx=pad, pady=pad)
cde.grid(row=1, column=4, padx=pad, pady=pad)
lpc.grid(row=2, column=2, padx=pad, pady=pad)
ple.grid(row=2, column=3, padx=pad, pady=pad)
epc.grid(row=2, column=0, padx=pad, pady=pad)
asc.grid(row=2, column=4, padx=pad, pady=pad)
cmd.grid(row=3, column=0, padx=pad, pady=pad, sticky='NSEW', columnspan=4)
ccb.grid(row=3, column=4, padx=pad, pady=pad, sticky='NSEW')
nil.grid(row=4, column=0, padx=pad, pady=pad)
nie.grid(row=4, column=1, padx=pad, pady=pad)
# events
for ctl in [ice, iae, cpe, npe, ple, lpc, epc, asc, cde]:
ctl.bind('<FocusOut>', do_update)
ctl.bind('<Enter>', do_update)
for var in [sudo, ep, lp, cl]:
var.trace_add('write', do_update)
# run
do_update(frm)
frm.focus()
frm.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment