Skip to content

Instantly share code, notes, and snippets.

@vovkkk
Last active December 31, 2015 13:09
Show Gist options
  • Save vovkkk/7990530 to your computer and use it in GitHub Desktop.
Save vovkkk/7990530 to your computer and use it in GitHub Desktop.
Simple skeleton to create launcher with buttons from tuple of tuples `self.cmds_to_launch`: first element ('bla') is label text to display on button; second element ('some command') is actual command to run when corresponding button pressed. Note that `self.cmds_to_launch` may contain any amount of tuples, provide no scrolling though.
#!python
# coding=utf-8
import Tkinter as tk
import ttk, subprocess
class Launcher(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.geometry("-0+30")
self.cmds_to_launch = (
('bla1', 'some command 1'),
('bla2', 'some command 2'),
('bla3', 'some command 3'),
('blaETC', 'some command ETC')
)
self.createWidgets()
def createWidgets(self):
for i, c in enumerate(self.cmds_to_launch):
vars(self)['b'+str(i)] = ttk.Button(text=c[0], command=lambda i=c[1]: subprocess.Popen(i), width=20).pack(anchor='n', expand='yes', fill='x', side='top')
if __name__ == "__main__":
Launcher().mainloop()
@vovkkk
Copy link
Author

vovkkk commented Dec 16, 2013

bla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment