""" Entry example """ from tkinter import Tk, Entry, Button from tkinter import TOP, X, LEFT, RIGHT from quitter import Quitter def fetch(): ''' Prints the Entry content ''' print('Input => "%s"' % ent.get()) # get text root = Tk() ent = Entry(root) ent.insert(0, 'Type words here') # set text ent.pack(side=TOP, fill=X) # grow horiz ent.focus() # save a click ent.bind('<Return>', (lambda __: fetch())) # on enter key btn = Button(root, text='Fetch', command=fetch) # and on button btn.pack(side=LEFT) Quitter(root).pack(side=RIGHT) root.mainloop()
demoModules = ['demoDlg', 'demoCheck', 'demoRadio', 'demoScale'] parts = [] def addComponents(root): for demo in demoModules: module = __import__(demo) # import by name string part = module.Demo(root, bd=6, relief=RIDGE) # attach, config instance #part.config(bd=2, relief=GROOVE) # config when created part.pack(side=LEFT, expand=YES, fill=BOTH) # grow, stretch with window parts.append(part) # change list in-place def dumpState(): for part in parts: # run demo report if any print(part.__module__ + ':', end=' ') if hasattr(part, 'report'): part.report() else: print('none') root = Tk() # make explicit root first root.title('Frames') Label(root, text='Multiple Frame demo', bg='white').pack() Button(root, text='States', command=dumpState).pack(fill=X) Quitter(root).pack(fill=X) addComponents(root) root.mainloop()
def tools(self): frame = Frame(master=self) frame.pack(side=RIGHT) Button(master=frame, text='State', command=self.report).pack(fill=X) Quitter(master=frame).pack(fill=X)
def makeform(root, fields): form = Frame(root) left = Frame(form) right = Frame(form) form.pack(fill=X) left.pack(side=LEFT) right.pack(side=RIGHT, expand=YES, fill=X) variables = [] for field in fields: lab = Label(left, width=5, text=field) ent = Entry(right) lab.pack(side=TOP) ent.pack(side=TOP, fill=X) var = StringVar() ent.config(textvariable=var) var.set('enter here') variables.append(var) return variables if __name__ == '__main__': root = Tk() vars = makeform(root, fields) Button(root, text='fetch', command=(lambda: fetch(vars))).pack(side=LEFT) Quitter(root).pack(side=LEFT) root.bind('<Return>', (lambda event: fetch(vars))) root.mainloop()
def tools(self): frm = Frame(self) frm.pack(side=RIGHT) Button(frm, text='State', command=self.report).pack(fill=X) Quitter(frm).pack(fill=X)
demoModules = ['demoDlg', 'demoCheck', 'demoRadio', 'demoScale'] parts = [] def addComponents(root): for demo in demoModules: module = __import__(demo) part = module.Demo(root) part.config(bd=2, relief=GROOVE) part.pack(side=LEFT, expand=YES, fill=BOTH) parts.append(part) def dumpState(): for part in parts: print(part.__module__ + ':', end=' ') if hasattr(part, 'report'): part.report() else: print('None') root = Tk() root.title('Frames') Label(master=root, text='Multiple frame demo', bg='white').pack() Button(master=root, text='States', command=dumpState).pack(fill=X) Quitter(master=root).pack(fill=X) addComponents(root) root.mainloop()
for pick in picks: rad = Radiobutton(master=self, text=pick, value=pick, variable=self.var) rad.pack(side=side, anchor=anchor, expand=YES) def state(self): return self.var.get() if __name__ == '__main__': root = Tk() lng = Checkbar(root, ['Python', 'C#', 'Java', 'C++']) gui = Radiobar(root, ['win', 'x11', 'mac'], side=TOP, anchor=NW) tgl = Checkbar(root, ['All']) gui.pack(side=LEFT, fill=Y) lng.pack(side=TOP, fill=X) tgl.pack(side=LEFT) lng.config(relief=GROOVE, bd=2) gui.config(relief=RIDGE, bd=2) def allstates(): print(gui.state(), lng.state(), tgl.state()) from quitter import Quitter Quitter(master=root).pack(side=RIGHT) Button(master=root, text='Peek', command=allstates).pack(side=RIGHT) root.mainloop()
def SetElements(self): '''Sets up the the GUI elements''' Label(self, text='Earthquakes', bg='azure', height=2, pady=2, font='Helvetica 22 bold').grid(row=0, column=0, rowspan=2, columnspan=14, sticky=W + E + S + N) #Zoom box bounds Label(self, text='Bounds of zoom box [lon/lat]', bg='azure', height=4, pady=2, padx=1, font='Helvetica 14 bold').grid(row=11, column=1, columnspan=4, sticky=W + E + S + N) Ncord = Entry(self) Ncord.grid(row=12, column=2, columnspan=1, sticky=E) Label(self, text='Northeastern corner').grid(row=12, column=1, columnspan=1, sticky=W) self.userentries['Northeast_box'] = Ncord Scord = Entry(self) Scord.grid(row=13, column=2, columnspan=1, sticky=E) Label(self, text='Southwestern corner').grid(row=13, column=1, columnspan=1, sticky=W) self.userentries['Southwest_box'] = Scord Button(self, text='Zoom', pady=1, padx=1, command=self.zoomin).grid(row=14, column=1, sticky=W + S + E + N, columnspan=1) Button(self, text='Reset', pady=1, padx=1, command=self.resetzoom).grid(row=14, column=2, sticky=W + S + E + N, columnspan=1) Button(self, text='Draw', pady=1, padx=1, command=self.drawbox).grid(row=14, column=3, sticky=W + S + E + N, columnspan=1) #Drawing profiles Label(self, text='Bounds of profile [lon/lat]', bg='azure', height=4, pady=2, padx=1, font='Helvetica 14 bold').grid(row=11, column=6, columnspan=4, sticky=W + E + S + N) Stcord = Entry(self) Stcord.grid(row=12, column=7, columnspan=1, sticky=E) Label(self, text='Start:').grid(row=12, column=6, columnspan=3, sticky=W) self.userentries['profile_start'] = Stcord Edcord = Entry(self) Edcord.grid(row=13, column=7, columnspan=1, sticky=E) Label(self, text='End:').grid(row=13, column=6, columnspan=3, sticky=W) self.userentries['profile_end'] = Edcord Button(self, text='Plot profile', pady=1, padx=1, command=self.plotprofile).grid(row=14, column=6, sticky=W + S + E + N, columnspan=4) #Event labels #For setting the magnitude range Label(self, text='Event options', bd=5, bg='azure', height=4, pady=2, padx=1, font='Helvetica 14 bold').grid(row=11, column=11, columnspan=4, sticky=W + E + S + N) Evtmags = Entry(self) Evtmags.grid(row=12, column=12, columnspan=2, sticky=E) Label(self, text='Event magnitude range [min-max]').grid(row=12, column=11, columnspan=1, sticky=W) self.userentries['magrange'] = Evtmags #For setting the time range Evttime = Entry(self) Evttime.grid(row=13, column=12, columnspan=2, sticky=E) Label(self, text='Event start date [yyyy-mm-dd]').grid(row=13, column=11, columnspan=1, sticky=W) self.userentries['evttime'] = Evttime Button(self, text='Set', pady=1, padx=1, command=lambda: self.setquakesmanual(userbox=True)).grid( row=14, column=11, sticky=W + S + E + N, columnspan=1) Button(self, text='Reset', pady=1, padx=1, command=self.removemapobjs).grid(row=14, column=12, sticky=W + S + E + N, columnspan=1) #Set up the label showing when the datasets are refreshed: the current time goes into that label self.timer = StringVar() Label(self, textvariable=self.timer, bg='azure', height=1, pady=1, padx=1, font='Helvetica 10 bold').grid(row=0, column=0, columnspan=4, sticky=W + E + S + N) self.timer.set('Updated %s' % str(time.asctime())) self.quakeinfo = StringVar() Label(self, textvariable=self.quakeinfo, bg='azure', height=1, padx=1, pady=1, font='Helvetica 10 bold').grid(row=0, column=8, columnspan=4, sticky=W + E + S + N) self.quakeinfo.set('Displaying: M%s to M%s' % (self.minmag, self.maxmag)) self.timeinfo = StringVar() Label(self, textvariable=self.timeinfo, bg='azure', height=1, padx=1, pady=1, font='Helvetica 10 bold').grid(row=0, column=6, columnspan=2, sticky=W + E + S + N) self.timeinfo.set('Displaying past %.2f days' % ((self.now - self.starttime) / (24 * 3600))) Quitter(self).grid(row=0, column=13, sticky=E)
from tkinter import * from tkinter.colorchooser import askcolor from quitter import Quitter def setBgColor(): (tripple, hexstr) = askcolor() if hexstr: print(hexstr) push.config(bg=hexstr) root = Tk() push = Button(root,text='Set background color',command=setBgColor) push.config(height=3, font=('times',20,'bold')) push.pack(expand=YES, fill=BOTH) quitter = Quitter() root.mainloop()
from Tkinter import * from quitter import Quitter demoModules = ['demoDlg', 'demoCheck', 'demoRadio', 'demoScale'] parts = [] def addComponents(root): for demo in demoModules: module = __import__(demo) # import by name string part = module.Demo(root) # attach an instance part.config(bd=2, relief=GROOVE) part.pack(side=LEFT, fill=BOTH) parts.append(part) # change list in-place def dumpState(): for part in parts: # run demo report if any print part.__module__ + ':', if hasattr(part, 'report'): part.report() else: print 'none' root = Tk() # default toplevel window Label(root, text='Multiple Frame demo', bg='white').pack() Button(root, text='States', command=dumpState).pack(fill=X) Quitter(root).pack(expand=YES, fill=X) addComponents(root) mainloop()
# Label(frame1,text='批量修改文件名',fg='red').pack(side=RIGHT) # ExtractFileName(frame2).pack(side=LEFT) # ChangeFileName(frame2).pack(side=RIGHT) # Quitter(frame3).grid(row=0,column=0) # Label(frame3,text='Made by JohnYang',font=('times',10,'roman'),fg='blue').grid(row=0,column=1) # root.mainloop() # except Exception as ex: # ex_type,ex_val,ex_stack=sys.exc_info() # print(ex_type) # print(ex_val) root = Tk() root.title('BRN1.0') root.resizable(0, 0) # root.iconbitmap(bitmap='BatchReName.ico') # root.wm_iconbitmap(bitmap='BatchReName.ico') frame1 = Frame(root) frame1.pack(side=TOP) frame2 = Frame(root) frame2.pack(side=TOP) frame3 = Frame(root) frame3.pack(side=BOTTOM) Label(frame1, text='批量获取文件名', fg='red').pack(side=LEFT) Label(frame1, text='批量修改文件名', fg='red').pack(side=RIGHT) ExtractFileName(frame2).pack(side=LEFT) ChangeFileName(frame2).pack(side=RIGHT) Quitter(frame3).grid(row=0, column=0) Label(frame3, text='Made by JohnYang', font=('times', 10, 'roman'), fg='blue').grid(row=0, column=1) root.mainloop()
def __init__(self, parent=None): Frame.__init__(self, parent) # game variables self.wordlist = ['monkey', 'zebra', 'giraffe', 'tiger', 'elephant', 'iguana', 'hippopotamus', 'rhinoceros', 'chimpanzee', 'orangutan', 'hyena', 'gorilla', 'leopard', 'bobcat', 'flamingo', 'alligator', 'crocodile', 'parrot'] self.pics = ['img/Hangman0.png', 'img/Hangman1.png', 'img/Hangman2.png', 'img/Hangman3.png', 'img/Hangman4.png', 'img/Hangman5.png', 'img/Hangman6.png'] self.secret_word = self.getWord() self.missed_letters = '' self.correct_letters = '' self.count = 0 # create game directions directions = Label(self, text="Guess my secret word!") directions.config(height=2, fg='white', bg='tomato') directions.pack(side=TOP, fill=X) # create space for the secret word word_space = Label(self, height=5) word_display = self.showWord(word_space) word_space.pack(side=TOP, fill=X, pady=10) # create a space for strike/ missed letter information miss = Frame(self) start_pic = PIL.Image.open(self.pics[0]) start_load = PIL.ImageTk.PhotoImage(start_pic) strike_pics = Label(miss, image=start_load) strike_pics.image = start_load strike_pics.pack(side=LEFT) miss_lets = Label(miss) miss_lets.pack(side=RIGHT) miss.pack(side=TOP) # create an entry for your guess guess_space = Frame(self) guess_space.config(bg='lime green') var = StringVar() guess_dir = Label(guess_space, text="Pick a letter:") guess_dir.config(bg='lime green') guess_dir.pack(side=LEFT, padx=10, pady=10) guess_ent = Entry(guess_space, textvariable=var) guess_ent.config(bg='gold') guess_ent.pack(side=RIGHT, padx=10, pady=10) guess_space.pack(side=TOP, pady=5) # create a button to enter guess guess_btn = Button(self, text='GUESS') guess_btn.config(command=(lambda: self.turn(var.get(), word_space, directions, strike_pics, miss_lets))) guess_btn.pack(side=TOP, fill=X, padx=10) # create buttons for play again and quit stop_space = Frame(self) new_game = Button(stop_space, text='New Game') new_game.config(command=(lambda: self.new_game(word_space, directions, strike_pics, miss_lets, start_load))) new_game.pack(side=LEFT, padx=10) quit = Quitter(stop_space).pack(side=RIGHT) stop_space.pack(side=TOP, fill=X)