def __init__(self, root, gua64): self.cntoint = { u'少阳-----': '1', u'少阴-- --': '2', u'老阳--O--': '3', u'老阴--X--': '4' } self.tfont = tkFont.Font(family='Fixdsys', size=25, weight=tkFont.BOLD) self.gfont = tkFont.Font(family='Fixdsys', size=13, weight=tkFont.BOLD) self.dgua = [] # 动爻 self.ygua = [] # 原始卦 self.bbgua = [] # 变卦 self.yguastr = [] # 原始卦 self.gua = [] # 只有12的卦 self.pabout = True # 右键显示消失淮南标题 self.guax = 200 self.guay = 100 self.liushen = { '甲': 0, '乙': 0, '丙': 1, '丁': 1, '戊': 2, '己': 3, '庚': 4, '辛': 4, '壬': 5, '癸': 5 } self.liushencn = ['青龙', '朱雀', '勾陈', '腾蛇', '白虎', '玄武'] self.tiangan = { '甲': 1, '乙': 2, '丙': 3, '丁': 4, '戊': 5, '己': 6, '庚': 7, '辛': 8, '壬': 9, '癸': 10 } self.dizhi = { '子': 1, '丑': 2, '寅': 3, '卯': 4, '辰': 5, '巳': 6, '午': 7, '未': 8, '申': 9, '酉': 10, '戌': 11, '亥': 12 } self.kongwangzu = [ '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥' ] self.root = root self.root.title(u'===六爻排盘===[淮南内部专用]') self.root.minsize(550, 380) self.root.maxsize(550, 380) self.canvas = Canvas(root, width=460, height=380, bg='gray') # self.picyang=PhotoImage(file='tk\\yang.gif') # self.picyin=PhotoImage(file='tk\\yin.gif') self.canvas.place(relx=0, rely=0) self.com = {} for i in xrange(6): self.com[i] = Combobox(root, state='readonly') self.com[i]['values'] = (u'少阳-----', u'少阴-- --', u'老阳--O--', u'老阴--X--') self.com[i].current(0) self.com[i].place(relx=0.85, rely=0.36 - 0.07 * i, width=80) bt1 = Button(self.root, text=u'排盘', command=self.paipan) bt2 = Button(self.root, text=u'清除', command=self.cls) l1 = Label(self.root, text=u'右键水印') l1.place(x=480, y=327) # bt1.place(relx=0.85,rely=0.35+0.7) # bt1.pack(side='right') bt1.place(x=467, y=170, width=78) bt2.place(x=467, y=350, width=78) self.date() # 干支 # =========================== self.root.bind('<Button-3>', self.about)
if sys.version_info < (3, 0): from Tkinter import Tk, Label, Button, LEFT, RIGHT else: from tkinter import Tk, Label, Button, LEFT, RIGHT def exit_btn_callback(evt): """Callback function to handle the button click event. :param Event evt: the instance of class Event from tkinter module. """ print("Inside exit_btn_callback. Event object is: {0}".format(evt)) if __name__ == '__main__': # Create the main window or Tk instance mainwin = Tk() mainwin.geometry("140x40") # Create a label widget and 'pack' it in a row (or column) lbl = Label(mainwin, text="Hello World!", bg='yellow') lbl.pack(side=LEFT) exit_button = Button(mainwin, text='Exit') # Bind the button click event to function exit_btn_callback exit_button.bind("<Button-1>", exit_btn_callback) exit_button.pack(side=RIGHT) mainwin.mainloop()
REGU = 'regu' SIGNS = { 'do not enter ': CRIT, 'railroad crossing': WARN, '55\nspeed limit': REGU, 'wrong way': CRIT, 'merging traffic': WARN, 'one way': REGU } critCB = lambda: showerror('Error', "Error Button Pressed!") warnCB = lambda: showwarning('Warnning', 'Warnning Button Pressed!') infoCB = lambda: showinfo('Info', 'Info Button Pressed!') top = Tk() top.title('Road Signs') Button(top, text='QUIT', command=top.quit, bg='red', fg='black').pack() MyButton = pto(Button, top) CritButton = pto(MyButton, command=critCB, bg='white', fg='red') WarnButton = pto(MyButton, command=warnCB, bg='goldenrod1') ReguButton = pto(MyButton, command=infoCB, bg='white') for eachSign in SIGNS: signType = SIGNS[eachSign] cmd = '%sButton(text=%r%s).pack(fill=X,expand=True)' % (signType.title( ), eachSign, '.upper()' if signType == CRIT else '.title()') eval(cmd) top.mainloop()
f = open(fn, 'U') except IOError, e: from cStringIO import StringIO f = StringIO(DEMO) en.delete(0, 'end') if fn.lower() == 'demo': en.insert(0,fn) else: import os en.insert(0,r"DEMO (can't open %s: %s)" % (os.path.join(os.getcwd(), fn), str(e))) en.update_idletasks() txt2ppt(line.rstrip() for line in f) f.close() if __name__ == '__main__': tk = Tk() lb = Label(tk, text='Enter file [or "DEMO"]:') lb.pack() en = Entry(tk) en.bind('<Return>', _start) en.pack() en.focus_set() quit = Button(tk, text='QUIT', command=tk.quit, fg='white', bg='red') quit.pack(fill='x', expand=True) tk.mainloop()
def __init__(self, port, pin1, pin2, pin3, pin4, pin5): # Setting up Arduino self.arduino = Arduino(port) self.servo1 = pin1 self.servo2 = pin2 self.servo3 = pin3 self.servo4 = pin4 self.servo5 = pin5 self.arduino.digital[self.servo1].mode = SERVO self.arduino.digital[self.servo2].mode = SERVO self.arduino.digital[self.servo3].mode = SERVO self.arduino.digital[self.servo4].mode = SERVO self.arduino.digital[self.servo5].mode = SERVO # Setting up Database Connect path = 'C:/Users/Mohamad/Desktop/db/servo_2d.db' self.Connect = lite.connect(path) self.servo1OldVal = 0 self.servo2OldVal = 0 self.servo3OldVal = 0 self.servo4OldVal = 0 self.servo5OldVal = 0 self.root = Tkinter.Tk() self.root.geometry('600x600') # GUI variables self.servo1Val = IntVar() self.servo2Val = IntVar() self.servo3Val = IntVar() self.servo4Val = IntVar() self.servo5Val = IntVar() self.pointName = StringVar() # GUI Components servo1_slider = Tkinter.Scale(self.root, label='Servo 1', length=400, from_=0, to_=360, orient=Tkinter.VERTICAL, variable=self.servo1Val) servo1_slider.grid(column=1, row=2) servo2_slider = Tkinter.Scale(self.root, label='Servo 2', length=400, from_=0, to_=180, orient=Tkinter.VERTICAL, variable=self.servo2Val) servo2_slider.grid(column=2, row=2) servo3_slider = Tkinter.Scale(self.root, label='Servo 3', length=400, from_=0, to_=180, orient=Tkinter.VERTICAL, variable=self.servo3Val) servo3_slider.grid(column=3, row=2) servo4_slider = Tkinter.Scale(self.root, label='Servo 4', length=400, from_=0, to_=180, orient=Tkinter.VERTICAL, variable=self.servo4Val) servo4_slider.grid(column=4, row=2) servo5_slider = Tkinter.Scale(self.root, label='Servo 5', length=400, from_=0, to_=60, orient=Tkinter.VERTICAL, variable=self.servo5Val) servo5_slider.grid(column=5, row=2) self.btnSave = Button(self.root, text='Save', command=self.onSaveClicked) self.btnSave.grid(column=1, row=0) self.btnGet = Button(self.root, text='Get', command=self.onGetClicked) self.btnGet.grid(column=6, row=0) self.pName = Entry(self.root, textvariable=self.pointName) self.pName.grid(column=0, row=0) self.root.after(100, self.onSliderChange) self.root.mainloop()
def home(self): self.frame1 = Frame(self.root, width=750, height=350, padx=250, bg="black") self.frame2 = Frame(self.root, height=250, width=750, bg="black", padx=25) self.root.wm_minsize(width=750, height=666) self.root.configure(bg="black") self.frame1.pack_propagate(0) self.frame1.update() self.frame1.configure(pady=self.frame1.cget("height") / 2.5) logo = PhotoImage(file="logo.gif") starth = Button(self.frame1, text="Hard", bg="orange", padx=25, pady=5, font=Font(family="comic sans MS", size=10), command=lambda: self.callgame(40)) startm = Button(self.frame1, text="Medium", bg="teal", padx=25, pady=5, font=Font(family="comic sans MS", size=10), command=lambda: self.callgame(60)) starte = Button(self.frame1, text="Easy", bg="orange", padx=25, pady=5, font=Font(family="comic sans MS", size=10), command=lambda: self.callgame(75)) self.frame2.pack_propagate(0) exp = """ This is a game in which the arrow keys are used to move the snake around and to get points""" exf = Font(family="comic sans MS", size=20) Label(self.frame2, image=logo, bg="black", text=exp, padx=10).pack(side="right") Label(self.frame2, fg="white", bg="black", text=exp, justify="left", font=exf).pack(side="left") starte.grid(row=0, columnspan=2) startm.grid(row=0, columnspan=2, column=4, padx=18) starth.grid(row=0, columnspan=2, column=8) head = Font(family="comic sans MS", size=30) self.H = Label(self.root, text="SNAKES", font=head, fg="orange", bg="black", pady=10) self.H.pack() self.frame2.pack(expand=True) self.frame1.pack(expand=True) self.root.mainloop()
def __init__(self, master): ##Inititilize Main self.master = master ##Define master master.title ("GUI Name") ##Create Title for GUI Window master.geometry("816x504") ##Define Window Size master.resizable (width = False, height = False)##Disable Max Button on Window master.columnconfigure(0,minsiz=187,weight=1) ##Column Definition (size) master.columnconfigure(1,minsiz=306,weight=1) ##Column Definition (size) master.columnconfigure(2,minsiz=160.3536,weight=1) ##Column Definition (size) master.columnconfigure(3,minsiz=160.3536,weight=1) ##Column Definition (size) master.rowconfigure(0,minsiz=98.2464,weight=1) ##Row Definition (size) master.rowconfigure(1,minsiz=323.2512,weight=1) ##Row Definition (size) master.rowconfigure(2,minsiz=56.6784,weight=1) ##Row Definition (size) master.rowconfigure(3,minsiz=39.3216,weight=1) ##Row Definition (size) self.projectNameLabel=projectNameLabel=Label(master,text='Project Name:',font=('BoldCourier',16)) ##Label Widget for projectNameEntry Box projectNameLabel.grid(row=0,column=0) ##Grid Label self.projectNameEntry=projectNameEntry=Entry(master,text='Enter Name Of Project',font=('Courier',16)) ##Entry Widget for Entering Name Of Project projectNameEntry.grid(row=0,column=1) ##Gid Entry Widget projectNameEntry.focus() ##Set Curser To Entry Widget self.includeStartingFilesVariable=includeStartingFilesVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.includeStartingFiles=includeStartingFiles=Checkbutton(master,text='Include\nStarting Files',borderwidth=2,relief='groove',variable=includeStartingFilesVariable,font=('Courier',16)) ##Checkbutton Widget for Including Starting Files includeStartingFiles.grid(row=0,column=2, columnspan=2) ##Grid Checkbutton Widget self.folderFrame=folderFrame=Frame(master,width=462, height=342, borderwidth=2,relief='groove') ##Frame Widget to Create Better GUI Layout folderFrame.grid(row=1,column=0,rowspan=2,columnspan=2) ##Grid Frame Widget folderFrame.columnconfigure(0,minsize=156,weight=1) ##Column Definition (size) folderFrame.columnconfigure(1,minsize=12.9984,weight=1) ##Column Definition (size) folderFrame.columnconfigure(2,minsize=149.0016,weight=1) ##Column Definition (size) folderFrame.columnconfigure(3,minsize=144,weight=1) ##Column Definition (size) folderFrame.rowconfigure(0,minsize=36,weight=1) ##Row Definition (size) folderFrame.rowconfigure(1,minsize=34.6656,weight=1) ##Row Definition (size) folderFrame.rowconfigure(2,minsize=42,weight=1) ##Row Definition (size) folderFrame.rowconfigure(3,minsize=12.9984,weight=1) ##Row Definition (size) folderFrame.rowconfigure(4,minsize=42,weight=1) ##Row Definition (size) folderFrame.rowconfigure(5,minsize=12.9984,weight=1) ##Row Definition (size) folderFrame.rowconfigure(6,minsize=42,weight=1) ##Row Definition (size) folderFrame.rowconfigure(7,minsize=12.9984,weight=1) ##Row Definition (size) folderFrame.rowconfigure(8,minsize=42,weight=1) ##Row Definition (size) folderFrame.rowconfigure(9,minsize=12.9984,weight=1) ##Row Definition (size) folderFrame.rowconfigure(10,minsize=49.872,weight=1) ##Row Definition (size) self.folderFrameLabel=folderFrameLabel=Label(folderFrame,text='Folders To Include',font=('BoldCourier',16)) ##Label Widget for Frame folderFrameLabel.grid(row=0,column=0,columnspan=4) ##Grid Label Widget self.mainFolderLabel=mainFolderLabel=Label(folderFrame,text='Main Folders',font=('BoldCourier',12)) ##Label Widget for Main Folders mainFolderLabel.grid(row=1,column=0) ##Grid Label Widget self.divider0=divider0=Frame(folderFrame,width=2,height=280,borderwidth=1,relief='sunken') ##Frame to act as Divider for Better GUI Layout divider0.grid(row=1,column=1,rowspan=10) ##Grid Divider self.subFolderLabel=subFolderLabel=Label(folderFrame,text='Sub-Folders',font=('BoldCourier',12)) ##Label Widget for Sub-Folders subFolderLabel.grid(row=1,column=2,columnspan=2) ##Grid Label Widget self.firmwareMainVariable=firmwareMainVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.firmwareMain=firmwareMain=Checkbutton(folderFrame,width=10,text='Firmware',borderwidth=2,relief='groove',anchor='w',variable=firmwareMainVariable,font=('Courier',12)) ##Checkbutton Widget for Firmware Main Folder firmwareMain.grid(row=2,column=0) ##Grid Ceckbutton Widget self.firmwareResourcesVariable=firmwareResourcesVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.firmwareResources=firmwareResources=Checkbutton(folderFrame,width=12,text='Resources',borderwidth=2,relief='groove',anchor='w',variable=firmwareResourcesVariable,font=('Courier',12)) ##Checkbutton Widget for Firmware-Resources Sub-Folder firmwareResources.grid(row=2,column=2) ##Grid Ceckbutton Widget self.firmwareArchiveVariable=firmwareArchiveVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.firmwareArchive=firmwareArchive=Checkbutton(folderFrame,width=8,text='Archive',borderwidth=2,relief='groove',anchor='w',variable=firmwareArchiveVariable,font=('Courier',12)) ##Checkbutton Widget for Firmware-Archive Sub-Folder firmwareArchive.grid(row=2,column=3) ##Grid Ceckbutton Widget self.divider1=divider1=Frame(folderFrame,width=400,height=2,borderwidth=1,relief='sunken') ##Frame to act as Divider for Better GUI Layout divider1.grid(row=3,column=0,columnspan=4) ##Grid Divider self.hardwareMainVariable=hardwareMainVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.hardwareMain=hardwareMain=Checkbutton(folderFrame,width=10,text='Hardware',borderwidth=2,relief='groove',anchor='w',variable=hardwareMainVariable,font=('Courier',12)) ##Checkbutton Widget for Hardware Main Folder hardwareMain.grid(row=4,column=0) ##Grid Ceckbutton Widget self.hardwarePartsVariable=hardwarePartsVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.hardwareParts=hardwareParts=Checkbutton(folderFrame,width=12,text='Parts',borderwidth=2,relief='groove',anchor='w',variable=hardwarePartsVariable,font=('Courier',12)) ##Checkbutton Widget for Hardware-Parts Sub-Folder hardwareParts.grid(row=4,column=2) ##Grid Ceckbutton Widget self.hardwareArchiveVariable=hardwareArchiveVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.hardwareArchive=hardwareArchive=Checkbutton(folderFrame,width=8,text='Archive',borderwidth=2,relief='groove',anchor='w',variable=hardwareArchiveVariable,font=('Courier',12)) ##Checkbutton Widget for Hardware-Archive Sub-Folder hardwareArchive.grid(row=4,column=3) ##Grid Ceckbutton Widget self.divider2=divider2=Frame(folderFrame,width=400,height=2,borderwidth=1,relief='sunken') ##Frame to act as Divider for Better GUI Layout divider2.grid(row=5,column=0,columnspan=4) ##Grid Divider self.resourcesMainVariable=resourcesMainVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.resourcesMain=resourcesMain=Checkbutton(folderFrame,width=10,text='Resources',borderwidth=2,relief='groove',anchor='w',variable=resourcesMainVariable,font=('Courier',12)) ##Checkbutton Widget for Resources Main Folder resourcesMain.grid(row=6,column=0) ##Grid Ceckbutton Widget self.resourcesDatasheetsVariable=resourcesDatasheetsVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.resourcesDatasheets=resourcesDatasheets=Checkbutton(folderFrame,width=12,text='Datasheets',borderwidth=2,relief='groove',anchor='w',variable=resourcesDatasheetsVariable,font=('Courier',12)) ##Checkbutton Widget for Resources-Datasheets Sub-Folder resourcesDatasheets.grid(row=6,column=2) ##Grid Ceckbutton Widget self.resourcesArchiveVariable=resourcesArchiveVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.resourcesArchive=resourcesArchive=Checkbutton(folderFrame,width=8,text='Archive',borderwidth=2,relief='groove',anchor='w',variable=resourcesArchiveVariable,font=('Courier',12)) ##Checkbutton Widget for Resources-Archive Sub-Folder resourcesArchive.grid(row=6,column=3) ##Grid Ceckbutton Widget self.divider3=divider3=Frame(folderFrame,width=400,height=2,borderwidth=1,relief='sunken') ##Frame to act as Divider for Better GUI Layout divider3.grid(row=7,column=0,columnspan=4) ##Grid Divider self.softwareMainVariable=softwareMainVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.softwareMain=softwareMain=Checkbutton(folderFrame,text='Software',width=10,borderwidth=2,relief='groove',anchor='w',variable=softwareMainVariable,font=('Courier',12)) ##Checkbutton Widget for Software Main Folder softwareMain.grid(row=8,column=0) ##Grid Ceckbutton Widget self.softwareResourcesVariable=softwareResourcesVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.softwareResources=softwareResources=Checkbutton(folderFrame,width=12,text='Resources',borderwidth=2,relief='groove',anchor='w',variable=softwareResourcesVariable,font=('Courier',12)) ##Checkbutton Widget for Software-Resources Sub-Folder softwareResources.grid(row=8,column=2) ##Grid Ceckbutton Widget self.softwareArchiveVariable=softwareArchiveVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.softwareArchive=softwareArchive=Checkbutton(folderFrame,width=8,text='Archive',borderwidth=2,relief='groove',anchor='w',variable=softwareArchiveVariable,font=('Courier',12)) ##Checkbutton Widget for Software-Archive Sub-Folder softwareArchive.grid(row=8,column=3) ##Grid Ceckbutton Widget self.divider4=divider4=Frame(folderFrame,width=400,height=2,borderwidth=1,relief='sunken') ##Frame to act as Divider for Better GUI Layout divider4.grid(row=9,column=0,columnspan=4) ##Grid Divider self.archiveMainVariable=archiveMainVariable=BooleanVar() ##Boolean to Hold Value of Checkbutton self.archiveMain=archiveMain=Checkbutton(folderFrame,width=10,text='Archive',borderwidth=2,relief='groove',anchor='w',variable=archiveMainVariable,font=('Courier',12)) ##Checkbutton Widget for Archive Main Folder archiveMain.grid(row=10,column=0) ##Grid Ceckbutton Widget self.instructionFrame=instructionFrame=Frame(master,width=300,height=288,borderwidth=2,relief='groove') ##Frame for Instructions instructionFrame.grid(row=1,column=2,columnspan=2) ##Grid Frame self.instuctionLabel=instructionLabel=Label(instructionFrame,text='Project Name will\nbe used as Folder Name.\r\nFolder can be found on\nDesktop after Creation.',font=('BoldCourier',16)) ##Label Holding Instructions instructionLabel.grid(row=0,column=0,pady=80,padx=30) ##Grid Label self.cancelButton=cancelButton=Button(master,text='Cancel', width=42,height=108,font=('BoldCourier',16),foreground='red',command=self.CancelCommand) ##Button Widget to Cancel/Close Program cancelButton.grid(row=2,column=2,padx=10) ##Grid Button Widget self.createButton=createButton=Button(master,text='Create',width=42,height=108,font=('BoldCourier',16),foreground='green',command=self.CreateCommand) ##Button Widget to Create Folder Structure createButton.grid(row=2,column=3,padx=10) ##Grid Button Widget self.versionNumber=versionNumber=Label(text='Ver. 0.1') ##Label to Display Version Number versionNumber.grid(row=3,column=3) ##Grid Label Widget
tkMessageBox.showinfo('Warning', u'网址读取错误,请尝试使用浏览器读取网址判断是否可以打开') return if not title: tkMessageBox.showinfo('Warning', u'检测到非微信文章页面') return thread.start_new_thread(download, (url, title, picUrl)) tkMessageBox.showinfo('Info', u'已经成功加入队列') def download(url, title, picUrl): for sk in (r'\/:*?"<>|'): title = title.replace(sk, '') title = title.replace(' ', ' ') if not os.path.exists(title.encode('cp936')): os.mkdir(title.encode('cp936')) download_pic_from_url(picUrl, os.path.join(title, u'标题图')) for i, picUrl in enumerate(get_pic_url_from_url(url), 1): download_pic_from_url(picUrl, os.path.join(title, str(i))) TASK_STORAGE.append(title) mainWindow = Tk() button = Button(mainWindow, cnf = {'command': button_clicked, 'text': 'Download', 'justify': 'right', }) inputEntry = Entry(mainWindow, width=70) inputEntry.pack() button.pack() mainWindow.title(u'微信图片下载器') while 1: mainWindow.update_idletasks() mainWindow.update() try: tkMessageBox.showinfo('Info', u'读取成功,请打开"%s"文件夹查看'%TASK_STORAGE.pop()) except: pass
from Tkinter import Button from Tkinter import Tk from Tkinter import RAISED from tkMessageBox import showinfo top = Tk() def hello_there(): showinfo('TitleSpam', 'msg_spam') B1 = Button(top, text='hello', command=hello_there) B2 = Button(top, text='watch', relief=RAISED, cursor='watch') B3 = Button(top, relief=RAISED, bitmap="hourglass", anchor='w') B1.pack() B2.pack() B3.pack() top.mainloop()
def save_vid(self, compress=False, delete=False): saved_files = [] # check that videos have been initialized if len(self.vid_out) == 0: not_initialized_window = Tk() Label( not_initialized_window, text= "Video writer is not initialized. Please set up first to record a video." ).pack() Button(not_initialized_window, text="Ok", command=lambda: not_initialized_window.quit()).pack() not_initialized_window.mainloop() not_initialized_window.destroy() else: # check for frames before saving. if any video has not taken frames, delete all videos frames_taken = all([len(i) > 0 for i in self.frame_times]) # release video writer (saves file). # if no frames taken or delete specified, delete the file and do not save timestamp files; otherwise, save timestamp files. for i in range(len(self.vid_out)): self.vid_out[i].release() self.vid_out[i] = None if (delete) or (not frames_taken): os.remove(self.vid_file[i]) else: np.save(str(self.ts_file[i]), np.array(self.frame_times[i])) saved_files.append(self.vid_file[i]) saved_files.append(self.ts_file[i]) if compress: threading.Thread( target=lambda: self.compress_vid(i)).start() if (len(self.lv_ts) > 0) and (not delete): np.save(str(self.lv_file), np.array(self.lv_ts)) saved_files.append(self.lv_file) save_msg = "" if len(saved_files) > 0: save_msg = "The following files have been saved:" for i in saved_files: save_msg += "\n" + i elif delete: save_msg = "Video has been deleted, please set up a new video to take another recording." elif not frames_taken: save_msg = "Video was initialized but no frames were recorded.\nVideo has been deleted, please set up a new video to take another recording." if save_msg: save_window = Tk() Label(save_window, text=save_msg).pack() Button(save_window, text="Close", command=lambda: save_window.quit()).pack() save_window.mainloop() save_window.destroy() self.vid_out = [] self.frame_times = [] self.current_file_label['text'] = ""
def createGUI(self): self.window = Tk() self.window.title("Camera Control") cur_row = 0 self.camera = [] self.camera_entry = [] self.exposure = [] self.exposure_entry = [] for i in range(int(self.number_of_cams.get())): # drop down menu to select camera Label(self.window, text="Camera " + str(i + 1) + ": ").grid(sticky="w", row=cur_row, column=0) self.camera.append(StringVar()) self.camera_entry.append( ttk.Combobox(self.window, textvariable=self.camera[i])) self.camera_entry[i]['values'] = self.cam_names self.camera_entry[i].current(i) self.camera_entry[i].grid(row=cur_row, column=1) # inialize camera button if i == 0: Button(self.window, text="Initialize Camera 1", command=lambda: self.init_cam(0)).grid(sticky="nsew", row=cur_row + 1, column=0, columnspan=2) elif i == 1: Button(self.window, text="Initialize Camera 2", command=lambda: self.init_cam(1)).grid(sticky="nsew", row=cur_row + 1, column=0, columnspan=2) elif i == 2: Button(self.window, text="Initialize Camera 3", command=lambda: self.init_cam(2)).grid(sticky="nsew", row=cur_row + 1, column=0, columnspan=2) # change exposure self.exposure.append(StringVar()) self.exposure_entry.append( Entry(self.window, textvariable=self.exposure[i])) self.exposure_entry[i].grid(sticky="nsew", row=cur_row, column=2) if i == 0: Button(self.window, text="Set Exposure 1", command=lambda: self.set_exposure(0)).grid( sticky="nsew", row=cur_row + 1, column=2) elif i == 1: Button(self.window, text="Set Exposure 2", command=lambda: self.set_exposure(1)).grid( sticky="nsew", row=cur_row + 1, column=2) elif i == 2: Button(self.window, text="Set Exposure 3", command=lambda: self.set_exposure(2)).grid( sticky="nsew", row=cur_row + 1, column=2) # empty row Label(self.window, text="").grid(row=cur_row + 2, column=0) # end of camera loop cur_row = cur_row + 3 # Labview Channel Label(self.window, text="Labview Channel: ").grid(sticky="w", row=cur_row, column=0) self.labview_channel = StringVar(value="") self.labview_channel_entry = ttk.Combobox( self.window, textvariable=self.labview_channel) self.labview_channel_entry['values'] = tuple(self.labview_channel_list) self.labview_channel_entry.grid(sticky="nsew", row=cur_row, column=1) Button(self.window, text="Initialize Labview", command=self.init_labview).grid(sticky="nsew", row=cur_row + 1, column=0, columnspan=2) Button(self.window, text="End LV", command=self.end_labview).grid(sticky="nsew", row=cur_row + 1, column=2) cur_row += 2 # empty row Label(self.window, text="").grid(row=cur_row, column=0) cur_row += 1 # subject name Label(self.window, text="Subject: ").grid(sticky="w", row=cur_row, column=0) self.subject = StringVar() self.subject_entry = ttk.Combobox(self.window, textvariable=self.subject) self.subject_entry['values'] = tuple(self.mouse_list) self.subject_entry.grid(row=cur_row, column=1) cur_row += 1 # attempt Label(self.window, text="Attempt: ").grid(sticky="w", row=cur_row, column=0) self.attempt = StringVar(value="1") self.attempt_entry = ttk.Combobox(self.window, textvariable=self.attempt) self.attempt_entry['values'] = tuple(range(1, 10)) self.attempt_entry.grid(row=cur_row, column=1) cur_row += 1 # type frame rate Label(self.window, text="Frame Rate: ").grid(sticky="w", row=cur_row, column=0) self.fps = StringVar() self.fps_entry = Entry(self.window, textvariable=self.fps) self.fps_entry.insert(END, '100') self.fps_entry.grid(sticky="nsew", row=cur_row, column=1) cur_row += 1 # output directory Label(self.window, text="Output Directory: ").grid(sticky="w", row=cur_row, column=0) self.output = StringVar() self.output_entry = ttk.Combobox(self.window, textvariable=self.output) self.output_entry['values'] = self.output_dir self.output_entry.grid(row=cur_row, column=1) Button(self.window, text="Browse", command=self.browse_output).grid(sticky="nsew", row=cur_row, column=2) cur_row += 1 # set up video Button(self.window, text="Set Up Video", command=self.set_up_vid).grid(sticky="nsew", row=cur_row, column=0, columnspan=2) cur_row += 1 Label(self.window, text="Current :: ").grid(row=cur_row, column=0, sticky="w") self.current_file_label = Label(self.window, text="") self.current_file_label.grid(row=cur_row, column=1, sticky="w") cur_row += 1 # empty row Label(self.window, text="").grid(row=cur_row, column=0) cur_row += 1 # record button Label(self.window, text="Record: ").grid(sticky="w", row=cur_row, column=0) self.record_on = IntVar(value=0) self.button_on = Radiobutton(self.window, text="On", selectcolor='green', indicatoron=0, variable=self.record_on, value=1, command=self.start_record).grid( sticky="nsew", row=cur_row, column=1) self.button_off = Radiobutton(self.window, text="Off", selectcolor='red', indicatoron=0, variable=self.record_on, value=0).grid(sticky="nsew", row=cur_row + 1, column=1) self.release_vid0 = Button( self.window, text="Save Video", command=lambda: self.save_vid(compress=False)).grid(sticky="nsew", row=cur_row, column=2) self.release_vid1 = Button( self.window, text="Compress & Save Video", command=lambda: self.save_vid(compress=True)).grid(sticky="nsew", row=cur_row + 1, column=2) self.release_vid2 = Button( self.window, text="Delete Video", command=lambda: self.save_vid(delete=True)).grid(sticky="nsew", row=cur_row + 2, column=2) cur_row += 3 # close window/reset GUI Label(self.window).grid(row=cur_row, column=0) self.reset_button = Button(self.window, text="Reset GUI", command=self.selectCams).grid(sticky="nsew", row=cur_row + 1, column=0, columnspan=2) self.close_button = Button(self.window, text="Close", command=self.close_window).grid( sticky="nsew", row=cur_row + 2, column=0, columnspan=2)
def set_up_vid(self): if len(self.vid_out) > 0: vid_open_window = Tk() Label( vid_open_window, text= "Video is currently open! \nPlease release the current video (click 'Save Video', even if no frames have been recorded) before setting up a new one." ).pack() Button(vid_open_window, text="Ok", command=lambda: vid_open_window.quit()).pack() vid_open_window.mainloop() vid_open_window.destroy() return # check if camera set up if len(self.cam) == 0: cam_check_window = Tk() Label( cam_check_window, text= "No camera is found! \nPlease initialize camera before setting up video." ).pack() Button(cam_check_window, text="Ok", command=lambda: cam_check_window.quit()).pack() cam_check_window.mainloop() cam_check_window.destroy() else: month = datetime.datetime.now().month month = str(month) if month >= 10 else '0' + str(month) day = datetime.datetime.now().day day = str(day) if day >= 10 else '0' + str(day) year = str(datetime.datetime.now().year) date = year + '-' + month + '-' + day self.out_dir = self.output.get() if not os.path.isdir(os.path.normpath(self.out_dir)): os.makedirs(os.path.normpath(self.out_dir)) # create output file names self.vid_file = [] self.base_name = [] self.ts_file = [] cam_name_nospace = [] this_row = 3 for i in range(len(self.cam)): cam_name_nospace.append(self.cam_name[i].replace(' ', '')) self.base_name.append(cam_name_nospace[i] + '_' + self.subject.get() + '_' + date + '_') self.vid_file.append( os.path.normpath(self.out_dir + '/' + self.base_name[i] + self.attempt.get() + '.avi')) # check if file exists, ask to overwrite or change attempt number if it does if i == 0: self.overwrite = False if os.path.isfile(self.vid_file[i]): self.ask_overwrite = Tk() def quit_overwrite(ow): self.overwrite = ow self.ask_overwrite.quit() Label( self.ask_overwrite, text="File already exists with attempt number = " + self.attempt.get() + ".\nWould you like to overwrite the file? ").pack( ) Button(self.ask_overwrite, text="Overwrite", command=lambda: quit_overwrite(True)).pack() Button(self.ask_overwrite, text="Cancel & pick new attempt number", command=lambda: quit_overwrite(False)).pack() self.ask_overwrite.mainloop() self.ask_overwrite.destroy() if self.overwrite: self.vid_file[i] = os.path.normpath( self.out_dir + '/' + self.base_name[i] + self.attempt.get() + '.avi') else: return else: self.vid_file[i] = self.vid_file[0].replace( cam_name_nospace[0], cam_name_nospace[i]) self.ts_file.append(self.vid_file[i].replace('.avi', '.npy')) self.ts_file[i] = self.ts_file[i].replace( cam_name_nospace[i], 'TIMESTAMPS_' + cam_name_nospace[i]) self.current_file_label['text'] = self.subject.get( ) + '_' + date + '_' + self.attempt.get() # create video writer dim = self.cam[i].get_image_dimensions() if len(self.vid_out) >= i + 1: self.vid_out[i] = cv2.VideoWriter( self.vid_file[i], cv2.VideoWriter_fourcc(*'DIVX'), int(self.fps.get()), dim) else: self.vid_out.append( cv2.VideoWriter(self.vid_file[i], cv2.VideoWriter_fourcc(*'DIVX'), int(self.fps.get()), dim)) if self.lv_task is not None: self.lv_file = self.ts_file[0].replace( 'TIMESTAMPS_' + cam_name_nospace[0], 'LABVIEW') # create video writer self.frame_times = [] for i in self.ts_file: self.frame_times.append([]) self.lv_ts = [] self.setup = True
str5 = StringVar(value='Umar bin Khattab') E5 = Entry(my_app, textvariable=str5) E5.grid(row=4, column=1) L6 = Label(my_app, text='Motto') L6.grid(row=5, column=0) str6 = StringVar(value='When Autumn Breeze Come We Will Meet Again') E6 = Entry(my_app, textvariable=str6) E6.grid(row=5, column=1) def close(): my_app.destroy() B = Button(my_app.quit(), text='close', command=close) B.grid(row=6, column=1) my_app.mainloop() ## activity 2 ## ##from Tkinter import Tk, Label, Entry, Button, StringVar ##from Tkinter import LEFT, RIGHT ## ## ##my_app = Tk(className = 'Calculator') ## ##L1 = Label(my_app, text='first number') ##L1.grid(row=0 , column=0 ) ##str1 = StringVar()
del RMST[:] global RSMT del RSMT[:] global GMST del GMST[:] global GSMT del GSMT[:] RMSTtext.set("-----") RSMTtext.set("-----") GMSTtext.set("-----") GSMTtext.set("-----") canvas.delete("all") master = Canvas(tk) but_frame = Frame(master) button1 = Button(but_frame, text = "RMST", command = computeRMST) button1.configure(width=9, activebackground = "blue", relief = RAISED) button1.pack(side=TOP) var = StringVar() var.set("Distance:") Label(but_frame, textvariable=var).pack() RMSTtext = StringVar() label1 = Label(but_frame, textvariable=RMSTtext) label1.pack() Label(but_frame, textvariable="").pack() button2 = Button(but_frame, text = "RSMT", command = computeRSMT) button2.configure(width=9, activebackground = "blue", relief = RAISED) button2.pack(side=TOP) Label(but_frame, textvariable=var).pack() RSMTtext = StringVar() label2 = Label(but_frame, textvariable=RSMTtext)
def __init__(self, master): master.title('Univention Lizenz Generator') self.master = master self.logoframe = Frame(self.master, bg='red') self.logoframe.pack(side=TOP, fill=X, expand=YES) self.lftopframes = LabelFrame(self.master) self.lftopframes.pack(side=TOP, fill=X, expand=YES) self.lframe = Frame(self.lftopframes) self.rframe = Frame(self.lftopframes) self.lframe.pack(side=LEFT, fill=X, expand=YES) self.rframe.pack(side=RIGHT, fill=X, expand=YES) self.bframe = Frame(self.master) self.bframe.pack(fill=X) self.kname = StringVar() self.kname.set('test') self.chkevar = IntVar() self.chkevar.set('1') self.chkivar = IntVar() self.chkovar = IntVar() self.chkdvar = IntVar() self.exday = StringVar() self.exmonth = StringVar() self.exyear = StringVar() self.getdate() # set date to localdate (month+3) try: self.logo = PhotoImage(file='/var/www/head_logo.gif') except TclError: # fall back to 64x64 white self.logo = PhotoImage(data='R0lGODdhQABAAIAAAP///wAAACwAAAAAQABAAAACRYSPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrhdQAAA7') # self.logo.pack() #muss man nicht packen??!! self.logolabel = Label(self.logoframe, image=self.logo, bg='#CC3300') self.logolabel.pack(side=LEFT, fill=X, expand=YES) self.lfname = LabelFrame(self.lframe, font=("Helvetica", 11), text='Kundenname:') self.lfname.pack(fill=X) self.ekname = Entry(self.lfname, textvariable=self.kname, width=30) self.ekname.pack(side=LEFT) self.lfdate = LabelFrame(self.lframe, font=("Helvetica", 11), text='Ablaufdatum (TT/MM/JJ):') self.lfdate.pack(fill=X) self.eexd = Entry(self.lfdate, textvariable=self.exday, width=2) self.eexd.pack(side=LEFT) self.eexm = Entry(self.lfdate, textvariable=self.exmonth, width=2) self.eexm.pack(side=LEFT) self.eexy = Entry(self.lfdate, textvariable=self.exyear, width=2) self.eexy.pack(side=LEFT) self.chkdate = Checkbutton(self.lfdate, text='Unbeschränkt', variable=self.chkdvar) self.chkdate.pack(side=RIGHT) self.lfchke = LabelFrame(self.lframe, font=("Helvetica", 11), text='Evaluationslizenz:') self.lfchke.pack(fill=X) self.chke = Checkbutton(self.lfchke, variable=self.chkevar) self.chke.pack(side=LEFT) self.lfchki = LabelFrame(self.lframe, font=("Helvetica", 11), text='Interne Lizenz:') self.lfchki.pack(fill=X) self.chki = Checkbutton(self.lfchki, variable=self.chkivar) self.chki.pack(side=LEFT) self.lfchko = LabelFrame(self.lframe, font=("Helvetica", 11), text='Altes Lizenzformat (vor 1.2-3):') self.lfchko.pack(fill=X) self.chko = Checkbutton(self.lfchko, variable=self.chkovar, command=self.makegrey) self.chko.pack(side=LEFT) self.kdn = StringVar() self.kdn.set('dc=univention,dc=de') self.lfdn = LabelFrame(self.rframe, font=("Helvetica", 11), text='Kunde DN:') self.lfdn.pack(fill=X) self.ekdn = Entry(self.lfdn, textvariable=self.kdn, width=30) self.ekdn.pack(side=LEFT) self.kmaxacc = IntVar() self.kmaxacc.set('999') self.kmaxgacc = IntVar() self.kmaxgacc.set('999') self.kmaxcli = IntVar() self.kmaxcli.set('999') self.kmaxdesk = IntVar() self.kmaxdesk.set('999') self.chkmaxaccvar = IntVar() self.chkmaxaccvar.set('0') self.chkmaxgaccvar = IntVar() self.chkmaxgaccvar.set('0') self.chkmaxclivar = IntVar() self.chkmaxclivar.set('0') self.chkmaxdeskvar = IntVar() self.chkmaxdeskvar.set('0') self.lfmaxacc = LabelFrame(self.rframe, font=("Helvetica", 11), text='Max. Accounts:') self.lfmaxacc.pack(fill=X) self.lfmaxgacc = LabelFrame(self.rframe, font=("Helvetica", 11), text='Max. Groupware Accounts:') self.lfmaxgacc.pack(fill=X) self.lfmaxcli = LabelFrame(self.rframe, font=("Helvetica", 11), text='Max. Clients:') self.lfmaxcli.pack(fill=X) self.lfmaxdesk = LabelFrame(self.rframe, font=("Helvetica", 11), text='Max. Univention Desktops:') self.lfmaxdesk.pack(fill=X) self.emaxacc = Entry(self.lfmaxacc, textvariable=self.kmaxacc) self.emaxacc.pack(side=LEFT) self.chkmaxacc = Checkbutton(self.lfmaxacc, text='Unbeschränkt', variable=self.chkmaxaccvar) self.chkmaxacc.pack(side=LEFT) self.emaxgacc = Entry(self.lfmaxgacc, textvariable=self.kmaxgacc) self.emaxgacc.pack(side=LEFT) self.chkmaxgacc = Checkbutton(self.lfmaxgacc, text='Unbeschränkt', variable=self.chkmaxgaccvar) self.chkmaxgacc.pack(side=LEFT) self.emaxcli = Entry(self.lfmaxcli, textvariable=self.kmaxcli) self.emaxcli.pack(side=LEFT) self.chkmaxcli = Checkbutton(self.lfmaxcli, text='Unbeschränkt', variable=self.chkmaxclivar) self.chkmaxcli.pack(side=LEFT) self.emaxdesk = Entry(self.lfmaxdesk, textvariable=self.kmaxdesk) self.emaxdesk.pack(side=LEFT) self.chkmaxdesk = Checkbutton(self.lfmaxdesk, text='Unbeschränkt', variable=self.chkmaxdeskvar) self.chkmaxdesk.pack(side=LEFT) self.bexit = Button(self.bframe, text='Beenden', command=self.quit) self.bexit.pack(side=RIGHT) self.bsave = Button(self.bframe, text='Lizenz erzeugen', command=self.generate) self.bsave.pack(side=RIGHT)
def __init__(self, master): self.fname="" #global variables self.t1=StringVar() self.t2=StringVar() self.t3=StringVar() self.t4=StringVar() self.t5=StringVar() self.var1=StringVar() self.var2=StringVar() self.var3=StringVar() self.var4=StringVar() self.var5=StringVar() #end mymaster = Frame(master, name='mymaster') # create Frame in "root" mymaster.pack(fill=BOTH) #min and max size of window #master.minsize(width=900, height=900) #master.maxsize(width=650, height=500) #end #title of window master.title("Airgraph-ng") #end #for the style of fonts self.customFont = tkFont.Font(family="Helvetica", size=12) self.myfont = tkFont.Font(family="Helvetica", size=10) self.myfont2 = tkFont.Font(family="Helvetica", size=8) self.headerfont=tkFont.Font(family="Helvetica", size=15,underline = True) self.myfontnew=tkFont.Font(family="Helvetica", size=11,underline = True) #end nb = Notebook(mymaster, name='nb') # create Notebook in "master" nb.pack(fill=BOTH, padx=2, pady=3) # fill "master" but pad sides #content frame self.frame_content = Frame(nb,name="frame_content", bg="lightsteelblue") self.frame_content.pack(fill=BOTH, side=TOP, expand=True) nb.add(self.frame_content, text="Filter-1") # add tab to Notebook # repeat for each tab self.frame_content7 = Frame(nb, name='frame_content7', bg="lightsteelblue") nb.add(self.frame_content7, text="Detect Devices") self.frame_content5 = Frame(nb, name='frame_content5', bg="lightsteelblue") nb.add(self.frame_content5, text="output") #End #frame content 7 Label(self.frame_content7, text = 'Airgraph-ng',font=self.headerfont, bg="midnightblue", fg="firebrick", padx=10, pady=10).grid(row = 0, column = 0) btndetect=Button(self.frame_content7, text = 'Detect', fg="cornflowerblue", command =self.canvas_detect, height=2, width=15, font=self.customFont).grid(row = 1, column = 0, padx = 5, pady = 5) btndbrowse=Button(self.frame_content7, text = 'Attach File', fg="cornflowerblue", command =self.browse_file, height=2, width=15, font=self.customFont).grid(row = 3, column = 0, padx = 5, pady = 5) self.lilnew1=Listbox(self.frame_content7,bg="black", fg="firebrick", font=self.myfont, selectmode=SINGLE, width=30, height=15) self.lilnew1.grid(row = 1, column = 1, rowspan=3) #End Label(self.frame_content, text = 'Airgraph-ng',font=self.headerfont, bg="midnightblue", fg="firebrick", padx=10, pady=10).grid(row = 0, column = 0) Label(self.frame_content, text = 'Options :',font=self.myfontnew, bg="midnightblue", fg="deepskyblue").grid(row = 1, column = 1) #Button(self.frame_content, text = 'ivs', command =self.canvas_detect, height=2, width=15, font=self.customFont).grid(row = 2, column = 0, padx = 5, pady = 5) #Button(self.frame_content, text = 'gpsd', command =self.canvas_detect, height=2, width=15, font=self.customFont).grid(row = 2, column = 1, padx = 5, pady = 5) #Button(self.frame_content, text = 'write', command =self.canvas_detect, height=2, width=15, font=self.customFont).grid(row = 2, column = 2, padx = 5, pady = 5) #command Listbox Label(self.frame_content5, text = 'Edit Command From Here',font=self.myfontnew, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 0, column = 0) TextCommandBox=Text(self.frame_content5, height=5, width=30) TextCommandBox.grid(row=1, column=0, padx=5, pady=5) self.output=Text(self.frame_content5,bg="black", fg="firebrick", font=self.myfont, height=20, width=42) self.output.grid(row = 0, column = 1, padx=50, pady=5, rowspan=3) btnsubmit=Button(self.frame_content5, width=15, height=2, text="Get Result", fg="cornflowerblue", command=self.mycallback) btnsubmit.grid(row=2, column=0) btnclear=Button(self.frame_content5, width=15, height=2, text="Clear Output", fg="cornflowerblue", command=self.clearoutput) btnclear.grid(row=3, column=0) #end self.C1 = Checkbutton(self.frame_content, text = "-i", fg="deepskyblue", \ onvalue = "-i", offvalue = "", height=1, \ width = 7, bg="midnightblue", font=self.customFont,variable=self.var1) self.C1.grid(row = 2, column = 0, padx = 5, pady = 5) self.t1=Text(self.frame_content,height=1,width = 20) self.t1.grid(row = 2, column = 1, padx = 5, pady = 5) l1=Label(self.frame_content, text = ': Input File',font=self.myfont, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 2, column = 2, padx = 5, pady = 5) self.C2 = Checkbutton(self.frame_content, text = "-o", fg="deepskyblue", \ onvalue = "-o", offvalue = "", height=1, \ width = 7, bg="midnightblue", font=self.customFont,variable=self.var2) self.C2.grid(row = 3, column = 0, padx = 5, pady = 5) self.t2=Text(self.frame_content,height=1,width = 20) self.t2.grid(row = 3, column = 1, padx = 5, pady = 5) l2=Label(self.frame_content, text = ': Output File',font=self.myfont, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 3, column = 2, padx = 5, pady = 5) self.C3 = Checkbutton(self.frame_content, text = "-g", fg="deepskyblue", \ onvalue = "-g", offvalue = "", height=1, \ width = 7, bg="midnightblue", font=self.customFont,variable=self.var3) self.C3.grid(row = 4, column = 0, padx = 5, pady = 5) self.t3=Text(self.frame_content,height=1,width = 20) self.t3.grid(row = 4, column = 1, padx = 5, pady = 5) l3=Label(self.frame_content, text = ': Graph Type',font=self.myfont, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 4, column = 2, padx = 5, pady = 5) self.C4 = Checkbutton(self.frame_content, text = "-a", fg="deepskyblue", \ onvalue = "-a", offvalue = "", height=1, \ width = 7, bg="midnightblue", font=self.customFont,variable=self.var4) self.C4.grid(row = 5, column = 0, padx = 5, pady = 5) self.t4=Text(self.frame_content,height=1,width = 20) self.t4.grid(row = 5, column = 1, padx = 5, pady = 5) l4=Label(self.frame_content, text = ': Print the about',font=self.myfont, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 5, column = 2, padx = 5, pady = 5) self.C5 = Checkbutton(self.frame_content, text = "-h", fg="deepskyblue", \ onvalue = "-h", offvalue = "", height=1, \ bg="midnightblue", font=self.customFont,variable=self.var5) self.C5.grid(row = 6, column = 0, padx = 5, pady = 5) self.t5=Text(self.frame_content,height=1,width = 20) self.t5.grid(row = 6, column = 1, padx = 5, pady = 5) l5=Label(self.frame_content, text = ': Print this help.',font=self.myfont, bg="midnightblue", fg="deepskyblue", justify=LEFT).grid(row = 6, column = 2, padx = 5, pady = 5)
def __init__(self, master): self.initComplete = 0 self.master = master self.x, self.y, self.w, self.h = -1, -1, -1, -1 # bind master to <Configure> in order to handle any resizing, etc. # postpone self.master.bind("<Configure>", self.Master_Configure) self.master.bind('<Enter>', self.bindConfigure) self.master.title("PyHatch GUI") self.master.resizable(0, 0) # Linux may not respect this dialogframe = Frame(master, width=810, height=630) dialogframe.pack() self.Shortdesc_Labelframe = LabelFrame( dialogframe, text="Short Description (1-liner)", height="90", width="718") self.Shortdesc_Labelframe.place(x=60, y=127) helv20 = tkFont.Font(family='Helvetica', size=20, weight='bold') self.Buildproject_Button = Button(dialogframe, text="Build Project", width="15", font=helv20) self.Buildproject_Button.place(x=492, y=10, width=263, height=68) self.Buildproject_Button.bind("<ButtonRelease-1>", self.Buildproject_Button_Click) self.Selectdir_Button = Button(dialogframe, text="<Select Directory>", width="15") self.Selectdir_Button.place(x=72, y=585, width=672, height=31) self.Selectdir_Button.bind("<ButtonRelease-1>", self.Selectdir_Button_Click) self.Author_Entry = Entry(dialogframe, width="15") self.Author_Entry.place(x=228, y=424, width=187, height=21) self.Author_Entry_StringVar = StringVar() self.Author_Entry.configure(textvariable=self.Author_Entry_StringVar) self.Author_Entry_StringVar.set("John Doe") self.Classname_Entry = Entry(dialogframe, width="15") self.Classname_Entry.place(x=192, y=73, width=165, height=21) self.Classname_Entry_StringVar = StringVar() self.Classname_Entry.configure( textvariable=self.Classname_Entry_StringVar) self.Classname_Entry_StringVar.set("MyClass") self.Copyright_Entry = Entry(dialogframe, width="15") self.Copyright_Entry.place(x=228, y=478, width=461, height=21) self.Copyright_Entry_StringVar = StringVar() self.Copyright_Entry.configure( textvariable=self.Copyright_Entry_StringVar) self.Copyright_Entry_StringVar.set("Copyright (c) 2013 John Doe") self.Email_Entry = Entry(dialogframe, relief="sunken", width="15") self.Email_Entry.place(x=228, y=505, width=458, height=21) self.Email_Entry_StringVar = StringVar() self.Email_Entry.configure(textvariable=self.Email_Entry_StringVar) self.Email_Entry_StringVar.set("*****@*****.**") self.GithubUserName_Entry = Entry(dialogframe, relief="sunken", width="15") self.GithubUserName_Entry.place(x=228, y=539, width=458, height=21) self.GithubUserName_Entry_StringVar = StringVar() self.GithubUserName_Entry.configure( textvariable=self.GithubUserName_Entry_StringVar) self.GithubUserName_Entry_StringVar.set("github_user_name") self.Funcname_Entry = Entry(dialogframe, width="15") self.Funcname_Entry.place(x=192, y=100, width=157, height=21) self.Funcname_Entry_StringVar = StringVar() self.Funcname_Entry.configure( textvariable=self.Funcname_Entry_StringVar) self.Funcname_Entry_StringVar.set("my_function") # License values should be correct format LICENSE_OPTIONS = tuple(sorted(CLASSIFIER_D.keys())) self.License_Entry_StringVar = StringVar() self.License_Entry = OptionMenu(dialogframe, self.License_Entry_StringVar, *LICENSE_OPTIONS) self.License_Entry.place(x=552, y=424, width=184, height=21) self.License_Entry_StringVar.set(LICENSE_OPTIONS[0]) self.Mainpyname_Entry = Entry(dialogframe, width="15") self.Mainpyname_Entry.place(x=168, y=37, width=196, height=21) self.Mainpyname_Entry_StringVar = StringVar() self.Mainpyname_Entry.configure( textvariable=self.Mainpyname_Entry_StringVar) self.Mainpyname_Entry_StringVar.set("main.py") self.Projname_Entry = Entry(dialogframe, width="15") self.Projname_Entry.place(x=168, y=10, width=194, height=21) self.Projname_Entry_StringVar = StringVar() self.Projname_Entry.configure( textvariable=self.Projname_Entry_StringVar) self.Projname_Entry_StringVar.set("MyProject") self.Shortdesc_Entry = Entry(dialogframe, width="15") self.Shortdesc_Entry.place(x=72, y=150, width=688, height=48) self.Shortdesc_Entry_StringVar = StringVar() self.Shortdesc_Entry.configure( textvariable=self.Shortdesc_Entry_StringVar) self.Shortdesc_Entry_StringVar.set("My project does this") # Status must be correct format self.Status_Entry_StringVar = StringVar() self.Status_Entry = OptionMenu(dialogframe, self.Status_Entry_StringVar, *DEV_STATUS_OPTIONS) self.Status_Entry.place(x=228, y=451, width=183, height=21) self.Status_Entry_StringVar.set(DEV_STATUS_OPTIONS[0]) self.Version_Entry = Entry(dialogframe, width="15") self.Version_Entry.place(x=552, y=451, width=184, height=21) self.Version_Entry_StringVar = StringVar() self.Version_Entry.configure(textvariable=self.Version_Entry_StringVar) self.Version_Entry_StringVar.set("0.1.1") self.Author_Label = Label(dialogframe, text="Author", width="15") self.Author_Label.place(x=96, y=424, width=112, height=22) self.Classname_Label = Label(dialogframe, text="Class Name", width="15") self.Classname_Label.place(x=60, y=73, width=112, height=22) self.Copyright_Label = Label(dialogframe, text="Copyright", width="15") self.Copyright_Label.place(x=96, y=478, width=113, height=23) self.Email_Label = Label(dialogframe, text="Email", width="15") self.Email_Label.place(x=96, y=505, width=113, height=23) self.GithubUserName_Label = Label(dialogframe, text="GithubUserName", width="15") self.GithubUserName_Label.place(x=96, y=539, width=113, height=23) self.Funcname_Label = Label(dialogframe, text="Function Name", width="15") self.Funcname_Label.place(x=60, y=100, width=112, height=22) self.License_Label = Label(dialogframe, text="License", width="15") self.License_Label.place(x=432, y=424, width=113, height=23) self.Longdesc_Label = Label(dialogframe, text="Paragraph Description", width="15") self.Longdesc_Label.place(x=216, y=220, width=376, height=22) self.Mainpyname_Label = Label(dialogframe, text="Main Python File", width="15") self.Mainpyname_Label.place(x=48, y=37, width=112, height=22) self.Projname_Label = Label(dialogframe, text="Project Name", width="15") self.Projname_Label.place(x=48, y=10, width=112, height=22) self.Selectdir_Label = Label( dialogframe, text="Select the Directory Below Which to Place Your Project", width="15") self.Selectdir_Label.place(x=156, y=567, width=536, height=24) self.Status_Label = Label(dialogframe, text="Status", width="15") self.Status_Label.place(x=96, y=451, width=114, height=24) self.Version_Label = Label(dialogframe, text="Version", width="15") self.Version_Label.place(x=432, y=451, width=113, height=23) self.Isclass_Radiobutton = Radiobutton(dialogframe, text="Class Project", value="Class Project", width="15", anchor=W) self.Isclass_Radiobutton.place(x=320, y=73, width=135, height=27) self.RadioGroup1_StringVar = StringVar() self.RadioGroup1_StringVar.set("Class Project") self.RadioGroup1_StringVar_traceName = \ self.RadioGroup1_StringVar.trace_variable("w", self.RadioGroup1_StringVar_Callback) self.Isclass_Radiobutton.configure(variable=self.RadioGroup1_StringVar) self.Isfunction_Radiobutton = Radiobutton(dialogframe, text="Function Project", value="Function Project", width="15", anchor=W) self.Isfunction_Radiobutton.place(x=320, y=100, width=135, height=27) self.Isfunction_Radiobutton.configure( variable=self.RadioGroup1_StringVar) lbframe = Frame(dialogframe) self.Text_1_frame = lbframe scrollbar = Scrollbar(lbframe, orient=VERTICAL) self.Text_1 = Text(lbframe, width="40", height="6", yscrollcommand=scrollbar.set) scrollbar.config(command=self.Text_1.yview) scrollbar.pack(side=RIGHT, fill=Y) self.Text_1.pack(side=LEFT, fill=BOTH, expand=1) self.Text_1_frame.place(x=72, y=250, width=665, height=160) # >>>>>>insert any user code below this comment for section "top_of_init" self.dirname = '<Select Directory>' self.Funcname_Entry.config(state=DISABLED) h = Hatch(projName='MyProject', mainDefinesClass='N') if h.author: self.Author_Entry_StringVar.set(h.author) if h.proj_license: self.License_Entry_StringVar.set(h.proj_license) if h.proj_copyright: self.Copyright_Entry_StringVar.set(h.proj_copyright) if h.email: self.Email_Entry_StringVar.set(h.email) if h.github_user_name: self.GithubUserName_Entry_StringVar.set(h.github_user_name) del h
def show(self, id, table): root2 = Tk() root2.title("Book Bank") root2.geometry("269x345") canvas = Canvas(root2) canvas.pack(fill=BOTH, expand=1) im = Image.open('wall4.jpg') img = ImageTk.PhotoImage(image=im) # Label(canvas,image=img).place(x=0, y=0) # Label(canvas, image=img, anchor=NW).place(x=0, y=0) canvas.create_image(0, 0, image=img, anchor=NW) Label(canvas, text=unicode("معلومات البائع", "utf-8"), bg='black', fg="white", width=50).pack(pady=7) sql = "select * from {} where id = {}".format(table, id) connect = self.connect_DataBase() cur = connect.cursor() try: cur.execute(sql) data = cur.fetchone() connect.commit() except Exception as e: connect.rollback() print e connect.close() file_like = BytesIO(data[2]) img1 = PIL.Image.open(file_like, mode='r').convert('RGB') im1 = img1.resize((130, 150), PIL.Image.ANTIALIAS) # to chage image size im = ImageTk.PhotoImage(im1) # canvas.create_image(60, 29, image=im, anchor=NW) Label(root2, image=im, anchor=NW).place(x=60, y=30) Label(root2, bg='black', fg='white', text="Book Name: {}".format(data[1])).place(x=59, y=188) Label(root2, bg='black', fg='white', text="Book Price: {} SR".format(data[5])).place(x=59, y=208) Label(root2, bg='black', fg='white', text="Seller Email:{}".format(data[3])).place(x=59, y=228) Label(root2, bg='black', fg='white', text="Phone Number:{}".format(data[4])).place(x=59, y=248) def Confirm(): tkMessageBox.showinfo( unicode("تأكيد", "utf-8"), unicode( " تم تأكيد طلبك بنجاح\n" "سيتم التواصل معك من قبل مالك الكتاب\n\n" "شكرا لك !", "utf-8")) connect = self.connect_DataBase() cur = connect.cursor() sql = "delete from {} where id = {}".format(table, id) cur.execute(sql) connect.commit() connect.close() root2.destroy() # self.Basic_frame() def Cancel(): root2.destroy() # self.Basic_frame() def back(): root2.destroy() from FrameSpecialty import Framespecialty Framespecialty().frame1() Button(root2, bg='black', fg='white', text=unicode("تأكيد", "utf-8"), command=Confirm, width=5).place(x=135, y=281) Button(root2, bg='black', fg='white', text=unicode("إلغاء", "utf-8"), command=Cancel, width=5).place(x=60, y=281) Button(root2, bg='black', fg='white', text=unicode("عودة", "utf-8"), command=back, width=5).place(x=97, y=310) root2.mainloop()
def _init_widgets(self): ## CEBALERT: now we can have multiple operations at the same time, ## status bar could be improved to show all tasks? # CEBALERT self.messageBar = self.status self.some_area = DockManager(self) self.some_area.pack(fill="both", expand=1) ### Balloon, for pop-up help self.balloon = tk.Balloon(self.content) ### Top-level (native) menu bar #self.menubar = tk.ControllableMenu(self.content) self.configure(menu=self.menubar) #self.menu_balloon = Balloon(topo.tkgui.root) # no menubar in tile yet # http://news.hping.org/comp.lang.tcl.archive/4679.html self.__simulation_menu() self.__create_plots_menu() self.refresh_plots_menu() self.__help_menu() ### Running the simulation run_frame = Frame(self.content) run_frame.pack(side='top', fill='x', padx=4, pady=8) self.run_frame = run_frame Label(run_frame, text='Run for: ').pack(side=LEFT) self.run_for_var = DoubleVar() self.run_for_var.set(1.0) run_for = tk.TaggedSlider(run_frame, variable=self.run_for_var, tag_width=11, slider_length=150, bounds=(0, 20000)) self.balloon.bind( run_for, "Duration to run the simulation, e.g. 0.0500, 1.0, or 20000.") run_for.pack(side=LEFT, fill='x', expand=YES) run_for.tag.bind("<Return>", self.run_simulation) # When return is pressed, the TaggedSlider updates itself...but we also want to run # the simulation in this case. run_frame.optional_action = self.run_simulation go_button = Button(run_frame, text="Go", command=self.run_simulation) go_button.pack(side=LEFT) self.balloon.bind(go_button, "Run the simulation for the specified duration.") self.step_button = Button(run_frame, text="Step", command=self.run_step) self.balloon.bind( self.step_button, "Run the simulation through the time at which the next events are processed." ) self.step_button.pack(side=LEFT) self.sizeright()
# -*- coding: UTF-8 -*- from Tkinter import Button, Label, END from Tix import Tk, Control, ComboBox top = Tk() top.tk.eval('package require Tix') lb = Label(top, text='Animals (in pairs; min: pair, max: dozen)') lb.pack() ct = Control(top, label='Number:', integer=True, max=12, min=2, value=6, step=2) ct.label.config(font=('Helvetica', 14, 'bold')) ct.pack() cb = ComboBox(top, label='Type:', editable=True) for animal in ('dog', 'cat', 'hamster', 'spider', 'python'): cb.insert(END, animal) cb.pack() qb = Button(top, text='Quit', command=top.quit, bg='red', fg='white') qb.pack() top.mainloop()
# remove unnecessary folders and files shutil.rmtree(foldername) shutil.rmtree('build') shutil.rmtree('dist') os.remove("main.spec") root.quit() def incorrect_version(): print 'Build process is cancelled because of incorrect version number' root.quit() version_title = Label(root, text='Glider-task-converter %s' % version, font=("Helvetica", 30)) question = Label(root, text="Is this the correct version number?", font=("Helvetica", 12)) stop = Button(root, command=incorrect_version, text='no') go_on = Button(root, command=correct_version, text='yes') version_title.grid(row=0, column=0, columnspan=2) question.grid(row=1, column=0, columnspan=2) stop.grid(row=2, column=0, sticky=E) go_on.grid(row=2, column=1, sticky=W) root.mainloop()
print "active:", test.index('active', 'row') print "anchor:", test.index('anchor', 'row') root = Tk() #root.tk.call('load', '', 'Tktable') var = ArrayVar(root) for y in range(-1, 4): for x in range(-1, 5): index = "%i,%i" % (y, x) var.set(index, index) label = Label(root, text="Proof-of-existence test for Tktable") label.pack(side='top', fill='x') quit = Button(root, text="QUIT", command=root.destroy) quit.pack(side='bottom', fill='x') test = Table(root, rows=10, cols=5, state='disabled', width=6, height=6, titlerows=1, titlecols=1, roworigin=-1, colorigin=-1, selectmode='browse', selecttype='row', rowstretch='unset',
def xit(): root.destroy() exit(0) root = Tk() root.geometry("320x240") root.title("RESULTS GENERATOR V2 -- KAILASH RAMESH") dl = Label(root, text="Enter DOB: ") de = Entry(root) ll = Label(root, text="Enter the Lower Limit: ") le = Entry(root) ul = Label(root, text="Enter the Upper Limit: ") ue = Entry(root) sub = Button(root, text="GENERATE!", command=operation) xyt = Button(root, text="EXIT", command=xit) mod = Button(root, text="Adjust Delays", command=dly) dl.place(x=20, y=40) de.place(x=160, y=40) ll.place(x=20, y=80) le.place(x=160, y=80) ul.place(x=20, y=120) ue.place(x=160, y=120) sub.place(x=80, y=170) xyt.place(x=165, y=170) mod.place(x=210, y=170) root.mainloop()
def render_add_remove(self): self.add_button = Button(self.master, text="Add ->", command=self.add_students) self.remove_button = Button(self.master, text="<- Remove", command=self.remove_students) self.add_button.grid(row=4, column=2, sticky=W+E+N+S) self.remove_button.grid(row=5, column=2, sticky=W+E+N+S)
def __init__(self, master): def center(win): win.update_idletasks() width = win.winfo_width() height = win.winfo_height() x = (win.winfo_screenwidth() // 4) - (width // 2) + 40 y = (win.winfo_screenheight() // 4) - (height // 2) + 40 win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) def callback(event): event.widget.focus_set() print "clicked at", event.x, event.y if self.add_tasks_flg.get() == 1: self.enter_task(event) master.title("Map Interface") master.minsize(width=1000, height=750) master.maxsize(width=1000, height=750) master.config(bg=BKG_COLOUR) self.master = master # Canvas for overlaying map self.map_canvas = Canvas(master, width=CANVAS_W, height=CANVAS_H, bg='gray85', highlightthickness=0) self.map_canvas.pack(side='right',padx=50) self.map_canvas.bind("<Button-1>", callback) global CANVAS_PTR CANVAS_PTR = self.map_canvas self.master.update() w = self.map_canvas.winfo_width() h = self.map_canvas.winfo_height() # Overlay a grid for i in range(0,w,SQ_SIZE): if i != 0: self.map_canvas.create_line(i,0,i,h,dash=1) for i in range(0,h,SQ_SIZE): if i != 0: self.map_canvas.create_line(0,i,w,i,dash=1) # Load in flame icon from flame.gif self.flame_icon = PhotoImage(file="flame.gif") # Load in the drone icon from drone.gif global DRONE_ICON DRONE_ICON = PhotoImage(file="drone.gif") buttons_frame = Canvas(master, width=163, height=140, bg=BUTTONS_BKG_COLOUR, highlightthickness=1, highlightbackground='dim grey') buttons_frame.place(x=40,y=230) # Define UI buttons self.add_tasks_flg = IntVar() self.add_tasks_b = Checkbutton(master, text="Add Tasks", variable=self.add_tasks_flg, highlightbackground=BUTTONS_BKG_COLOUR, background=BUTTONS_BKG_COLOUR) self.add_tasks_b.place(x=77,y=270) self.clear_wp_b = Button(master, text='Clear Tasks', command=self.clear_wp, highlightbackground=BUTTONS_BKG_COLOUR) self.clear_wp_b.config(width=10) self.clear_wp_b.place(x=65, y=300) ''' self.gen_wp_file_b = Button(master, text='Generate Waypoints File', command=self.gen_wp_file, highlightbackground=BKG_COLOUR) self.gen_wp_file_b.config(width=20) self.gen_wp_file_b.place(x=20, y=250) ''' ''' self.land_b = Button(master, text='Land', command=self.land, highlightbackground=BUTTONS_BKG_COLOUR) self.land_b.config(width=10) self.land_b.place(x=65, y=350) ''' # Set up coordinate system conversion and display corners of room: file_obj = open('antenna_locations.txt', 'r') anchors = [] for line in file_obj: cur_anchors = map(float, line.split()) anchors.append(cur_anchors) file_obj.close() anchors = (np.array(anchors)).T # Find largest (abs) x and y values to use a reference for conversion ratio x_vals = anchors[0] largest_x_val = x_vals[np.argmax(abs(x_vals))] y_vals = anchors[1] largest_y_val = y_vals[np.argmax(abs(y_vals))] if largest_x_val > largest_y_val: largest_y_val = largest_x_val else: largest_x_val = largest_y_val global m_per_pixel_x m_per_pixel_x = float(largest_x_val/(CANVAS_W/2)) global m_per_pixel_y m_per_pixel_y = float(largest_y_val/(CANVAS_H/2)) # Place antenna (anchors) on UI anchors = anchors.T for cur_anchor in anchors: x_pixel_loc = cur_anchor[0] / m_per_pixel_x + CANVAS_W/2 y_pixel_loc = -1*(cur_anchor[1] / m_per_pixel_y) + CANVAS_H/2 # Draw antenna @ location global ANTENNA_LIST antenna_id = self.map_canvas.create_oval(x_pixel_loc-15,y_pixel_loc-15,x_pixel_loc+15,y_pixel_loc+15,fill='red') self.master.update()
# only allow changes if the green-yellow-red-green sequencing # is followed) def red_light(): traffic_light.create_oval(10, 10, 190, 190, fill='red') def yellow_light(): traffic_light.create_oval(10, 10, 190, 190, fill='yellow') def green_light(): traffic_light.create_oval(10, 10, 190, 190, fill='green') # Create the three button widgets red_button = Button(traffic_window, text='Red', width=6, command=red_light) yellow_button = Button(traffic_window, text='Yellow', width=6, command=yellow_light) green_button = Button(traffic_window, text='Green', width=6, command=green_light) # Create the drawing canvas traffic_light = Canvas(traffic_window, width=200, height=200, bg='white') # Call the geometry manager to place the widgets onto # the window (in a grid arrangement, with a margin) margin_size = 5
def __init__(self,master,position,onClick): self.master=master self.position = position self.photo = PhotoImage(file="Assets/circle.gif") self.UiOption = Button(self.master, image=self.photo, background="white", command=lambda: onClick(position)) self.UiOption.grid(row=position.Row, column=position.Column)
d = float(str2.get()) hasil = c - d L4.config(text=hasil) def times(): e = float(str1.get()) f = float(str2.get()) hasil = e * f L4.config(text=hasil) def devide(): g = float(str1.get()) h = float(str2.get()) hasil = g / h L4.config(text=hasil) B1 = Button(my_app, text='+', command=plus) B1.grid(row=3, column=0) B2 = Button(my_app, text='-', command=minus) B2.grid(row=3, column=1) B3 = Button(my_app, text='x', command=times) B3.grid(row=3, column=2) B4 = Button(my_app, text=':', command=devide) B4.grid(row=3, column=3) my_app.mainloop()
def kali(): p = float(str1.get()) q = float(str2.get()) r = p * q L.config(text=r) def bagi(): p = float(str1.get()) q = float(str2.get()) r = p / q L.config(text=r) B1 = Button(my_app, text='+', command=tambah) B1.grid(row=2, column=0) B2 = Button(my_app, text='-', command=kurang) B2.grid(row=2, column=1) B3 = Button(my_app, text='x', command=kali) B3.grid(row=2, column=2) B4 = Button(my_app, text=':', command=bagi) B4.grid(row=2, column=3) L3 = Label(my_app, text='Hasil') L3.grid(row=3, column=1) L = Label(my_app, text='0') L.grid(row=3, column=2) my_app.mainloop()
def initUI(self): self.parent.title("Booru") self.pack(fill=Y, expand=0, side=LEFT) myicon = ImageTk.PhotoImage(file="sbooru.ico") self.current_booru_var = StringVar() self.mb = Menubutton(self, textvariable=self.current_booru_var, relief=RAISED, image=myicon, compound=LEFT) self.mb.image = myicon self.mb.pack(side=TOP) self.mb.menu = Menu(self.mb, tearoff=0) self.mb["menu"] = self.mb.menu self.current_booru_var.set("Safebooru") def change_booru(booru): self.current_booru = booru if self.current_booru == 0: self.current_booru_var.set("Danbooru") if self.current_booru == 1: self.current_booru_var.set("Safebooru") self.mb.menu.add_command(label="Danbooru", command=lambda: change_booru(0)) self.mb.menu.add_command(label="Safebooru", command=lambda: change_booru(1)) self.mb.pack() image = Image.open( get_image_from_internet_binary( u"%s%s" % (main_url, self.posts[0][u"preview_file_url"]))) photo = ImageTk.PhotoImage(image) self.label = Label(self, image=photo) self.label.image = photo self.label.pack(fill=Y, expand=0, side=TOP) self.lb = Listbox(self) for i in self.posts: self.lb.insert(END, i["id"]) self.lb.bind("<<ListboxSelect>>", self.onSelect) self.lb.pack(pady=15, fill=Y, expand=0, side=LEFT) self.description = Labelframe(self, text="Description", height=350, width=350) self.description.pack(pady=15, expand=0) #artist self.artist_v = StringVar() self.artist = Label(self.description, textvariable=self.artist_v, justify=LEFT, wraplength=350, anchor=W) self.artist.pack() #md5 self.md5_v = StringVar() self.md5 = Label(self.description, textvariable=self.md5_v, justify=LEFT, wraplength=350, anchor=W) self.md5.pack() #source self.source_v = StringVar() self.source = Label(self.description, textvariable=self.source_v, justify=LEFT, wraplength=350, anchor=W) self.source.pack() #wxh self.wxh_v = StringVar() self.wxh = Label(self.description, textvariable=self.wxh_v, justify=LEFT, wraplength=350, anchor=W) self.wxh.pack() #tags (for now all) self.tags_v = StringVar() self.tags = Label(self.description, textvariable=self.tags_v, justify=LEFT, wraplength=350, anchor=W) self.tags.pack() #uploader self.uploader_v = StringVar() self.uploader = Label(self.description, textvariable=self.uploader_v, justify=LEFT, wraplength=350, anchor=W) self.uploader.pack() idx = (0, 0) try: self.artist_v.set(u"Artist:\t%s" % self.posts[idx[0]][u"tag_string_artist"]) except KeyError: self.artist_v.set(u"Artist:\t") try: self.md5_v.set(u"MD5:\t%s" % self.posts[idx[0]][u"md5"]) except KeyError: self.md5_v.set(u"MD5:\t") try: self.source_v.set(u"Source:\t%s" % self.posts[idx[0]][u"source"]) except KeyError: self.source_v.set(u"Source:\t") try: self.wxh_v.set(u"Size:\t%sx%s" % (self.posts[idx[0]][u"image_width"], self.posts[idx[0]][u"image_height"])) except KeyError: self.wxh_v.set(u"Size:\t") try: self.tags_v.set(u"Tags:\t%s" % self.posts[idx[0]][u"tag_string"]) except KeyError: self.tags_v.set(u"Tags:\t") try: self.uploader_v.set(u"Uploader:\t%s" % self.posts[idx[0]][u"uploader_name"]) except KeyError: self.uploader_v.set(u"Uploader:\t") self.button_frame = Frame(self.description) self.button_frame.pack(fill=Y, expand=0, side=LEFT) def download_image_current(): def download(): urllib.urlretrieve( "%s%s" % (main_url, self.current_image[u"file_url"]), "%s_%s.%s" % (self.current_image[u"id"], self.current_image[u"md5"], self.current_image[u"file_ext"])) t1 = Thread(target=download, args=()) t1.start() self.download_button = Button(self.button_frame, text="Download", command=download_image_current) self.download_button.pack(side=LEFT) def bigger_preview(): image = Image.open( get_image_from_internet_binary( u"%s%s" % (main_url, self.current_image[u"file_url"]))) photo = ImageTk.PhotoImage(image) self.bigpreview = Toplevel(self) labelu = Label(self.bigpreview, image=photo) labelu.image = photo labelu.pack(fill=Y, expand=0, side=LEFT) self.preview_button = Button(self.button_frame, text="Preview", command=bigger_preview) self.preview_button.pack(side=RIGHT) def onRefresh(): def method(): query_args["page"] = self.current_page.get() self.posts = get_posts("posts.json", query_args) self.lb.delete(0, END) for i in self.posts: self.lb.insert(END, i["id"]) t1 = Thread(target=method, args=()) t1.start() self.refresh = Button(self.button_frame, text="Refresh posts", command=onRefresh) self.refresh.pack(side=LEFT) page_control = Frame(self) page_control.pack(pady=15, side=BOTTOM) self.current_page = IntVar() self.current_page.set(1) def forward_f(): self.current_page.set(self.current_page.get() + 1) onRefresh() forward = Button(page_control, text=">>", command=forward_f) forward.pack(side=RIGHT) def backward_f(): self.current_page.set((self.current_page.get() - 1) if ( self.current_page.get() - 1 > 0) else self.current_page.get()) onRefresh() backward = Button(page_control, text="<<", command=backward_f) backward.pack(side=LEFT) curpaglabl = Label(page_control, textvariable=self.current_page, background="orange") curpaglabl.pack(pady=15, side=BOTTOM)