def __init__(self, num_rows, num_cols, best_possible): self.rows = num_rows self.cols = num_cols self.expectedBest = best_possible # create the root and the canvas root = Tk() # local function to bind/unbind events self.bind = root.bind self.unbind = root.unbind # local function to change title self.updateTitle = root.title # local function to change cursor self.updateCursor = lambda x: root.config(cursor=x) # local function to start game self.start = root.mainloop # get screen width and height ws = root.winfo_screenwidth() hs = root.winfo_screenheight() # fix scaling for higher resolutions if max(self.canvasWidth / ws, self.canvasHeight / hs) < 0.45: self.scale = 2 self.canvas = Canvas(root, width=self.canvasWidth, height=self.canvasHeight) self.canvas.pack() # calculate position x, y x = (ws - self.canvasWidth) // 2 y = (hs - self.canvasHeight) // 2 root.geometry('%dx%d+%d+%d' % (self.canvasWidth, self.canvasHeight, x, y)) root.resizable(width=0, height=0) self.init() # set up keypress events root.bind("<Key>", self.keyPressed)
def __init__(self, *args, **kwargs): Tk.__init__(self, *args, **kwargs) container = Frame(self) self.title("3d Printer") #This fied is populated on the first view #and displayed on the second self.customer_id = StringVar() container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (CreateCustomerView, ExecuteScriptView): frame = F(container, self) self.frames[F] = frame # put all of the pages in the same location; # the one on the top of the stacking order # will be the one that is visible. frame.grid(row=0, column=0, sticky="nsew") self.model = CreateCustomerModel() self.show_frame(CreateCustomerView)
def demo(): from nltk import Nonterminal, ContextFreeGrammar nonterminals = 'S VP NP PP P N Name V Det' (S, VP, NP, PP, P, N, Name, V, Det) = [Nonterminal(s) for s in nonterminals.split()] grammar = ContextFreeGrammar.fromstring(""" S -> NP VP PP -> P NP NP -> Det N NP -> NP PP VP -> V NP VP -> VP PP Det -> 'a' Det -> 'the' Det -> 'my' NP -> 'I' N -> 'dog' N -> 'man' N -> 'park' N -> 'statue' V -> 'saw' P -> 'in' P -> 'up' P -> 'over' P -> 'with' """) def cb(grammar): print(grammar) top = Tk() editor = CFGEditor(top, grammar, cb) Label(top, text='\nTesting CFG Editor\n').pack() Button(top, text='Quit', command=top.destroy).pack() top.mainloop()
class TestBase(unittest.TestCase): def setUp(self): self.root = Tk() def tearDown(self): self.root.destroy()
def getFileInput(): root = Tk() root.withdraw() wordFile = filedialog.askopenfile(title="Open Word File", mode="r", parent=root) if wordFile is None: raise SystemExit return wordFile
def enable(self, app=None): """Enable event loop integration with Tk. Parameters ---------- app : toplevel :class:`Tkinter.Tk` widget, optional. Running toplevel widget to use. If not given, we probe Tk for an existing one, and create a new one if none is found. Notes ----- If you have already created a :class:`Tkinter.Tk` object, the only thing done by this method is to register with the :class:`InputHookManager`, since creating that object automatically sets ``PyOS_InputHook``. """ if app is None: try: from tkinter import Tk # Py 3 except ImportError: from Tkinter import Tk # Py 2 app = Tk() app.withdraw() self.manager.apps[GUI_TK] = app return app
def create(): root=Tk() root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) gui = Gui(mockControl(), root) gui.grid(sticky=E+W+S+N) return (root, gui)
def goodUser(): errorMsg = Tk() goodCRN = Label(errorMsg, text="Please enter a valid Villanova username") goodCRN.pack() errorMsg.mainloop()
def downloadsub(root_window: tkinter.Tk) -> None: for current_path in get_selected_movie_paths(): if not is_filetype_supported(current_path): tkinter.messagebox.showerror("Kipawa Sub Downloader", "This is not a supported movie file") else: try: if subdb_subtitles_exist(current_path): try: subdb.download_subtitles(current_path) tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Subtitles downloaded successfully!") except SubtitlesNotAvailableException: tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Sorry ! Better subtitles not found") elif opensubtitles_subs_exist(current_path): try: opensub.downloadsub(current_path) tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Subtitles downloaded succesdfully!") except SubtitlesNotAvailableException: tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Sorry ! Better subtitles not found") else: try: download_default_subtitles(current_path) tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Subtitles downloaded succesdfully!") except SubtitlesNotAvailableException: tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Sorry, no subtitles were found") except DownloadException as e: tkinter.messagebox.showinfo("Kipawa Sub Downloader", "Error downloading subtitles: " + str(e)) except ValueError as e: tkinter.messagebox.showinfo("Kipawa Sub Downloader", "There is a problem with this file: " + str(e)) root_window.quit()
def main(): root = Tk() f1 = tkinter.Frame(width=200, height=200) ex = Example(root) f1.pack(fill="both", expand=True, padx=20, pady=20) ex.place(in_=f1, anchor="c", relx=.5, rely=.5) root.mainloop()
def interactive_ask_diff(self, code, tmpfn, reffn, testid): from os import environ if 'UNITTEST_INTERACTIVE' not in environ: return False from tkinter import Tk, Label, LEFT, RIGHT, BOTTOM, Button from PIL import Image, ImageTk self.retval = False root = Tk() def do_close(): root.destroy() def do_yes(): self.retval = True do_close() phototmp = ImageTk.PhotoImage(Image.open(tmpfn)) photoref = ImageTk.PhotoImage(Image.open(reffn)) Label(root, text='The test %s\nhave generated an different' 'image as the reference one..' % testid).pack() Label(root, text='Which one is good ?').pack() Label(root, text=code, justify=LEFT).pack(side=RIGHT) Label(root, image=phototmp).pack(side=RIGHT) Label(root, image=photoref).pack(side=LEFT) Button(root, text='Use the new image -->', command=do_yes).pack(side=BOTTOM) Button(root, text='<-- Use the reference', command=do_close).pack(side=BOTTOM) root.mainloop() return self.retval
def main(): root = Tk() ex = Janela(root) root.geometry("300x250+300+300") center(root) root.mainloop()
def __init__(self, drs, size_canvas=True, canvas=None): """ :param drs: ``AbstractDrs``, The DRS to be drawn :param size_canvas: bool, True if the canvas size should be the exact size of the DRS :param canvas: ``Canvas`` The canvas on which to draw the DRS. If none is given, create a new canvas. """ master = None if not canvas: master = Tk() master.title("DRT") font = Font(family='helvetica', size=12) if size_canvas: canvas = Canvas(master, width=0, height=0) canvas.font = font self.canvas = canvas (right, bottom) = self._visit(drs, self.OUTERSPACE, self.TOPSPACE) width = max(right+self.OUTERSPACE, 100) height = bottom+self.OUTERSPACE canvas = Canvas(master, width=width, height=height)#, bg='white') else: canvas = Canvas(master, width=300, height=300) canvas.pack() canvas.font = font self.canvas = canvas self.drs = drs self.master = master
def interactive_ask_ref(self, code, imagefn, testid): from os import environ if 'UNITTEST_INTERACTIVE' not in environ: return True from tkinter import Tk, Label, LEFT, RIGHT, BOTTOM, Button from PIL import Image, ImageTk self.retval = False root = Tk() def do_close(): root.destroy() def do_yes(): self.retval = True do_close() image = Image.open(imagefn) photo = ImageTk.PhotoImage(image) Label(root, text='The test %s\nhave no reference.' % testid).pack() Label(root, text='Use this image as a reference ?').pack() Label(root, text=code, justify=LEFT).pack(side=RIGHT) Label(root, image=photo).pack(side=LEFT) Button(root, text='Use as reference', command=do_yes).pack(side=BOTTOM) Button(root, text='Discard', command=do_close).pack(side=BOTTOM) root.mainloop() return self.retval
def main(): logger.level = logs.DEBUG usage = 'PRACMLN Query Tool' parser = argparse.ArgumentParser(description=usage) parser.add_argument("-i", "--mln", dest="mlnarg", help="the MLN model file to use") parser.add_argument("-d", "--dir", dest="directory", action='store', help="the directory to start the tool from", metavar="FILE", type=str) parser.add_argument("-x", "--emln", dest="emlnarg", help="the MLN model extension file to use") parser.add_argument("-q", "--queries", dest="queryarg", help="queries (comma-separated)") parser.add_argument("-e", "--evidence", dest="dbarg", help="the evidence database file") parser.add_argument("-r", "--results-file", dest="outputfile", help="the results file to save") parser.add_argument("--run", action="store_true", dest="run", default=False, help="run with last settings (without showing GUI)") args = parser.parse_args() opts_ = vars(args) root = Tk() conf = PRACMLNConfig(DEFAULT_CONFIG) app = MLNQueryGUI(root, conf, directory=os.path.abspath(args.directory) if args.directory else None) if args.run: logger.debug('running mlnlearn without gui') app.infer(savegeometry=False, options=opts_) else: root.mainloop()
def __init__(self, app, kind='', icon_file=None, center=True): self.findIcon() Tk.__init__(self) if center: pass self.__app = app self.configBorders(app, kind, icon_file)
def destroy(self): instance_names = list(self.running_instance.keys()) for old_item in instance_names: if self.running_instance[old_item] is not None: self.running_instance[old_item].stop() del self.running_instance[old_item] Tk.destroy(self)
def savePreset(main, filename=None): if filename is None: root = Tk() root.withdraw() filename = simpledialog.askstring(title='Save preset', prompt='Save config file as...') root.destroy() if filename is None: return config = configparser.ConfigParser() fov = 'Field of view' config['Camera'] = { 'Frame Start': main.frameStart, 'Shape': main.shape, 'Shape name': main.tree.p.param(fov).param('Shape').value(), 'Horizontal readout rate': str(main.HRRatePar.value()), 'Vertical shift speed': str(main.vertShiftSpeedPar.value()), 'Clock voltage amplitude': str(main.vertShiftAmpPar.value()), 'Frame Transfer Mode': str(main.FTMPar.value()), 'Cropped sensor mode': str(main.cropParam.value()), 'Set exposure time': str(main.expPar.value()), 'Pre-amp gain': str(main.PreGainPar.value()), 'EM gain': str(main.GainPar.value())} with open(os.path.join(main.presetDir, filename), 'w') as configfile: config.write(configfile) main.presetsMenu.addItem(filename)
def main(): #abort shutdown abortShutdown() #load the application root = Tk() app = FullScreenApp(root) root.mainloop()
def gui_inputs(): """create gui interface and return the required inputs Returns ------- infile : str pathname to the shapefile to apply the split field : str name of the field in the shape file dest : str folder name to save the outputs """ # locate your input shapefile print("select your input file") root = Tk() infile = tkfd.askopenfilename(title = "Select your shapefile", initialdir = "C:/", filetypes = (("shapefile", "*.shp"), ("all files", "*.*"))) # define destination -folder- where output -shapefiles- will be written print("select your output dir") dest = tkfd.askdirectory(title = "Select your output folder", initialdir = "C:/") root.destroy() # choose field to split by attributes print("Select your field name") field_options = _extract_attribute_field_names(infile) field = create_field_form(field_options) print("selection done") return infile, field, dest
def test(): """ Kolorem czarnym są narysowane obiekty utworzone za pomocą klas fabrycznych. Kolorem czerwonym obiekty utworzone przy użyciu funkcji shapeFactory """ creator = RectangleCreator() rect = creator.factory("Rectangle",a=40,b=60) rect2 = shapeFactory("Rectangle",a=40,b=60, outline="#f00") creator = TriangleCreator() tri = creator.factory("Triangle",a=100,b=100,c=100) tri2 = shapeFactory("Triangle",a=100,b=100,c=100,outline="#f00") creator = SquareCreator() sq = creator.factory("Square",a=60) sq2 = shapeFactory("Square",a=60,outline="#f00") root = Tk() w = Window(root) w.drawShape(rect,100,100) w.drawShape(rect2,100,200) w.drawShape(tri,200,100) w.drawShape(tri2,200,200) w.drawShape(sq,370,100) w.drawShape(sq2,370,200) root.geometry("600x400+100+100") root.mainloop()
def main(options): """Create GUI and perform interactions.""" root = Tk() root.title('Oscilloscope GUI') gui = Tdsgui(root, options) print(type(gui)) root.mainloop()
class TkWindowMainLoop(Thread): '''class for thread that handles Tk window creation and main loop''' def __init__(self, client): Thread.__init__(self) self.window = None self.canvas = None self.client = client self.start() def callbackDeleteWindow(self): self.client.stop() def stop(self): self.window.quit() def run(self): self.window = Tk() self.canvas = Canvas(self.window, width=1024, height=768) self.canvas.pack() self.window.protocol("WM_DELETE_WINDOW", self.callbackDeleteWindow) self.window.mainloop() def getWindow(self): return self.window def getCanvas(self): return self.canvas
def _calltip_window(parent): # htest # import re from tkinter import Tk, Text, LEFT, BOTH root = Tk() root.title("Test calltips") width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) root.geometry("+%d+%d"%(x, y + 150)) class MyEditWin: # conceptually an editor_window def __init__(self): text = self.text = Text(root) text.pack(side=LEFT, fill=BOTH, expand=1) text.insert("insert", "string.split") root.update() self.calltip = CallTip(text) text.event_add("<<calltip-show>>", "(") text.event_add("<<calltip-hide>>", ")") text.bind("<<calltip-show>>", self.calltip_show) text.bind("<<calltip-hide>>", self.calltip_hide) text.focus_set() root.mainloop() def calltip_show(self, event): self.calltip.showtip("Hello world", "insert", "end") def calltip_hide(self, event): self.calltip.hidetip() MyEditWin()
def main(): root = Tk() root.withdraw() with filedialog.askopenfile(mode = "r", parent = root) as inputData: students = [] for line in inputData: firstName, lastName = line.split(',') lastName = lastName.strip() scores = [] scores = lastName.split(' ') lastName = scores.pop(0) while '' in scores: scores.remove('') for item in scores: if ' ' in item: if ' ' in item[:1]: newItem = item[1:] scores.insert(scores.index(item), newItem) scores.remove(item) item = newItem if "100" in item: first, second = item.split(' ') first = first.strip() second = second.strip() scores.insert(scores.index(item), first) scores.insert(scores.index(item) + 1, second) scores.remove(item) else: scores[scores.index(item)] = item.replace(' ', '') students.append(Student(firstName, lastName, scores)) students = sortList(students) longestNameLen = findLongestName(students) output(students, longestNameLen, os.path.basename(inputData.name))
def __init__(self, title="", message="", button="Ok", image=None, checkmessage="", style="clam", **options): """ Create a messagebox with one button and a checkbox below the button: parent: parent of the toplevel window title: message box title message: message box text button: message displayed on the button image: image displayed at the left of the message checkmessage: message displayed next to the checkbox **options: other options to pass to the Toplevel.__init__ method """ Tk.__init__(self, **options) self.resizable(False, False) self.title(title) s = Style(self) s.theme_use(style) if image: Label(self, text=message, wraplength=335, font="Sans 11", compound="left", image=image).grid(row=0, padx=10, pady=(10, 0)) else: Label(self, text=message, wraplength=335, font="Sans 11").grid(row=0, padx=10, pady=(10, 0)) b = Button(self, text=button, command=self.destroy) b.grid(row=2, padx=10, pady=10) self.var = BooleanVar(self) c = Checkbutton(self, text=checkmessage, variable=self.var) c.grid(row=1, padx=10, pady=0, sticky="e") self.grab_set() b.focus_set() self.wait_window(self)
def __init__(self,root): Tk.__init__(self,root) self.root = root self.MAX_F = 12 self.info = StringVar() self.sliders = [] self.parameters = [] self.filters = [] self.isAdvancedMode = False self.isWritting = False self.configFile = "config.xml" self.cw = ConfigWritter(self.configFile) if not isfile(self.configFile): self._createConfigFile() self.cp = ConfigParser(self.configFile) self._parseConfigFile() self.canvas = Canvas() self.canvas.pack(expand=YES,fill=BOTH) self.initialize()
def main(): q = Queue() root = Tk() root.geometry("400x350+300+300") Example(root, q) root.mainloop()
def ingresarUsuario(cls): cls.nombre="" def salir(): root.quit() def cargarArchivo(): cls.nombre=a.get() root.destroy() def obtenerN(): n=a.get() return (n) root = Tk() root.title('CargarDatos') a = StringVar() atxt = Entry(root, textvariable=a,width=20) cargar = Button(root, text="Cargar Archivo", command=cargarArchivo,width=15) salirB= Button(root, text ="Salir", command=root.destroy, width=10) atxt.grid(row=0, column=0) cargar.grid(row=1, column=0) salirB.grid(row=1,column=1) root.mainloop() return (obtenerN())
def save(): """This function will save the file. It will also save the day, too! You just might be safe with this one!""" from tkinter import Tk import tkinter.filedialog root = Tk() root.withdraw() fd = tkinter.filedialog.FileDialog(master=root,title='Project Celestia') savefile = fd.go() if savefile != None: import os.path, tkinter.dialog if os.path.exists(savefile): if os.path.isdir(savefile): tkinter.filedialog.FileDialog.master.bell() return savefile d = tkinter.dialog.Dialog(master=None,title='Hold your horses!', text='Are you sure you want to rewrite this file?' '\nI mean, I have already seen the file before...\n' '\n-Twilight Sparkle', bitmap='questhead',default=0,strings=('Eeyup','Nah')) if d.num != 1: return savefile else: FlashSentry.save_error() root.destroy()
def main(): root = Tk() root.geometry("750x300+300+300") app = ResearchFrame() root.mainloop()
self.image = ImageTk.BitmapImage(im, foreground="white") Label.__init__(self, master, image=self.image, bg="black", bd=0) else: # photo image self.image = ImageTk.PhotoImage(im) Label.__init__(self, master, image=self.image, bd=0) # # script interface if __name__ == "__main__": import sys if not sys.argv[1:]: print("Syntax: python viewer.py imagefile") sys.exit(1) filename = sys.argv[1] root = Tk() root.title(filename) im = Image.open(filename) UI(root, im).pack() root.mainloop()
from tkinter import messagebox, simpledialog, Tk # Create an if-main code block, *hint, type main then ctrl+space to auto-complete if __name__ == '__main__': # Make a new window variable, window = Tk() window = Tk() # Hide the window using the window's .withdraw() method window.withdraw() # 1. Create a variable to hold the user's score. Set it equal to zero. score = 0 # ASK A QUESTION AND CHECK THE ANSWER # // 2. Ask the user a question question1 = simpledialog.askstring(title='Question 1', prompt='What is 2+2?') # // 3. Use an if statement to check if their answer is correct if question1 == '4': score = score + 1 # // 4. if the user's answer was correct, add one to their score else: score = score - 1 # MAKE MORE QUESTIONS. Ask more questions by repeating the above # // Option: Subtract a point from their score for a wrong answer question2 = simpledialog.askstring(title='Question 2', prompt='What is 4+4?') if question2 == '8': score = score + 1 else: score = score - 1 str(score)
# update canvas dx = box[0] % self.tilesize dy = box[1] % self.tilesize for x in range(box[0] - dx, box[2] + 1, self.tilesize): for y in range(box[1] - dy, box[3] + 1, self.tilesize): try: xy, tile = self.tile[(x, y)] tile.paste(self.image.crop(xy)) except KeyError: pass # outside the image self.update_idletasks() # # main root = Tk() if len(sys.argv) != 2: print("Usage: painter file") sys.exit(1) im = Image.open(sys.argv[1]) if im.mode != "RGB": im = im.convert("RGB") PaintCanvas(root, im).pack() root.mainloop()
class GUI(Mot): def __init__(self): self.__word = Mot() self.__mainSize = "400x300" self.__gameSize = "400x300" self.__ortho = self.__word.getOrtho() self.__winning = True self.__essais = self.__word.getEssais() self.__fautes = 0 self.__auth = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'é', 'è', 'î', 'ê', 'û', 'ë', 'ô', ] def playMain(self): self.__main = Tk() self.__main.geometry(self.__mainSize) welcomeLabel = Label(self.__main, text="Bonjour et bienvenu dans un jeu de pendu", fg="blue") welcomeLabel.pack() buttonQuit1 = Button(self.__main, text="Quitter", fg="red", command=self.__main.destroy) buttonQuit1.pack() buttonPlay = Button( self.__main, text="Jouer", command=lambda: [self.__main.destroy(), self.playGame()]) buttonPlay.pack() self.__main.mainloop() def Verification(self): if self.__champ1.get() in self.__auth: if self.__champ1.get() not in self.__essais: self.__essais.append(self.__champ1.get()) if self.__champ1.get() in self.__essais: errorMsg = Label( self.__game, text="Vous ne devez entrer qu'une seule lettre") if self.__champ1.get() not in self.__ortho: self.__fautes += 1 else: errorMsg = Label(self.__game, text="Vous ne devez entrer qu'une seule lettre") errorMsg.pack() def playGame(self): while self.__winning: self.__game = Tk() self.__game.geometry(self.__gameSize) self.__winning, self.__cache = self.__word.motCache() self.__essais = self.__word.getEssais() motTiret = Label(self.__game, text=self.__cache) motTiret['text'] = self.__cache motTiret.pack() if not self.__winning: victoryMsg = Label(self.__game, text="Bravo vous avez gagné") victoryMsg.pack() self.__champ1 = Entry(self.__game, text="coucou", fg="black") self.__champ1.pack() tryButton = Button(self.__game, text="Proposer", fg="green", command=self.Verification) tryButton.pack() listeMots = Label(self.__game, text=self.__essais) listeMots.pack() if self.__fautes == 8: losingMsg = Label(self.__game, text="Vous avez perdu") losingMsg.pack() replayButton = Button( self.__game, text="rejouer", command=lambda: [self.__game.destroy(), self.playGame()]) replayButton.pack() buttonQuit3 = Button(self.__game, text="Quitter", fg="red", command=self.__game.destroy) buttonQuit3.pack() self.__game.mainloop()
from tkinter import Tk from tk.mainwindow import MainWindow root = Tk() app = MainWindow(master=root) app.mainloop() root.destroy()
def setUpClass(cls): cls.root = Tk() cls.text = Text(cls.root) cls.percolator = Percolator(cls.text)
def selectMessageFromInbox(path): Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing filename = askdirectory() # show an "Open" dialog box and return the path to the selected directory return filename
import app.gamewrapper as gw import app.gamedisp as gm from tkinter import Tk ##main code #initiate and display the minefield ms = gw.Minesweeper() #initiate the game window root = Tk() GD = gm.GameDisplay(root,ms) root.geometry("%dx%d" % (GD.WIDTH, GD.HEIGHT + 40)) root.mainloop()
listaNumeroComics = [comic.numero for comic in comicInVolumeList] self.listaAMostrar.clear() self.listaAMostrar = [] print(listaNumeroComics) for comic in comicInVolumeList: if comic.numero in listaNumeros: self.listaAMostrar.append(comic) for item in self.grillaComics.get_children(): self.grillaComics.delete(item) for comic in self.listaAMostrar: self.grillaComics.insert('', 0, '', values=(comic.numero,comic.titulo,comic.comicVineId)) if __name__ == '__main__': root = Tk() session = Entidades.Init.Session() pathComics=["E:\\Comics\\DC\\Action Comics\\Action Comics 420.cbr", "E:\\Comics\\DC\\Action Comics\\Action Comics 422.cbr", "E:\\Comics\\DC\\Action Comics\\Action Comics 423.cbr" ] ''' , "E:\\Comics\\DC\\Action Comics\\Action Comics 442.cbr", "E:\\Comics\\DC\\Action Comics\\Action Comics 447.cbr", "E:\\Comics\\DC\\Action Comics\\Action Comics 470.cbr", "E:\\Comics\\DC\\Action Comics\\Action Comics 473.cbr" ''' comics= [] for pathComic in pathComics: comic = session.query(ComicBook).filter(ComicBook.path ==pathComic).first()
abs(score_base['param'][param_key] - predict_base['param'][param_key]) for param_key in enhance_name_list ]) / len(enhance_name_list) def _calc_error_data(score_base_list: list, predict_base_list: list): assert len(score_base_list) == len(predict_base_list) return sum([_calc_param_error(score_base, predict_base) for score_base, predict_base in zip(score_base_list, predict_base_list)]) / \ len(score_base_list) if __name__ == "__main__": root = Tk() root.attributes('-topmost', True) root.withdraw() root.lift() root.focus_force() load_dir_dict = _get_load_dir_dict() predict_model_dict = \ { key: MODEL_BUILDER_DICT[model_type][UseType.PREDICTABLE]() for key, model_type in zip(MODEL_KEY_LIST, list(ModelType)) } for key, value in predict_model_dict.items():
def main(): root = Tk() Searcher(root) root.mainloop()
def __init__(self): root = Tk() root.title("SNAKE AND LADDERS") head = Frame(root) head.pack(side='top') body = Frame(root) body.pack() # ------------------------------------------------------- left = Frame(body) # THIS IS FOR LEFT SIDE OF THE BODY FRAME self.right = Frame(body) # THIS IS FOR RIGHT SIDE OF THE BODY FRAME left.pack(side='left') self.right.pack(side='right') # ------------------HEADING OF SNAKE AND LADDER --------------- # self.lb1 = Label(self.right, text="player 1's name") # self.lb2 = Label(self.right, text="player 2's name") # self.box1 = Entry(self.right) # self.box2 = Entry(self.right) img100 = Image.open("dice/dice6.png") # =======================Buttons==================================================== self.canvas = Canvas(self.right, height=img100.size[0], width=img100.size[0]) self.canvas.grid(row=1, column=1) self.player1 = Button(self.right, text='Player 1', bg='#03A235', command=self.player1_dice_throw) self.player2 = Button(self.right, text='Player 2', bg='#AF7135', state='disable', command=self.player2_dice_throw) # self.lb1.grid(row=0, column=0, pady=50) # self.lb2.grid(row=0, column=2, pady=50) # self.box1.grid(row=1, column=0) # self.box2.grid(row=1, column=2) self.player1.grid(row=2, column=0, pady=50) self.player2.grid(row=2, column=2, pady=50) # Disable colour #AF7135 # ---------------------------heading label for game---------------------------------- Label(head, text="Snake & Ladder", font=("times new roman", 48, "bold", "underline"), bg="snow", fg="green").pack() # ===================IMG0 WILL SET THE CANVAS SIZE FOR ALL THE CANVAS================= img0 = Image.open('cut_images/1.png') #--------------------button for players-------------------------------- # bt1=Button(self.right,text="Player 1") #PLAYER 1's button # bt1.pack(side='bottom') # bt2=Button(self.right,text="Player 2") # bt2.pack(side='bottom') # -------------------NOW THE CAN IS CREATING THE SNAKE AND LADDER BOARD----------------------- self.can1 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can1.grid(row=10, column=1) img1 = PhotoImage(file='cut_images/1.png') self.can1.create_image(0, 0, image=img1, anchor=NW) #--------------------------------------------------------------------------------- self.can2 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can2.grid(row=10, column=2) img2 = PhotoImage(file='cut_images/2.png') self.can2.create_image(0, 0, image=img2, anchor=NW) #--------------------------------------------------------------------------------- self.can3 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can3.grid(row=10, column=3) img3 = PhotoImage(file='cut_images/3.png') self.can3.create_image(0, 0, image=img3, anchor=NW) #--------------------------------------------------------------------------------- self.can4 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can4.grid(row=10, column=4) img4 = PhotoImage(file='cut_images/4.png') self.can4.create_image(0, 0, image=img4, anchor=NW) #--------------------------------------------------------------------------------- self.can5 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can5.grid(row=10, column=5) img5 = PhotoImage(file='cut_images/5.png') self.can5.create_image(0, 0, image=img5, anchor=NW) #--------------------------------------------------------------------------------- self.can6 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can6.grid(row=10, column=6) img6 = PhotoImage(file='cut_images/6.png') self.can6.create_image(0, 0, image=img6, anchor=NW) #--------------------------------------------------------------------------------- self.can7 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can7.grid(row=10, column=7) img7 = PhotoImage(file='cut_images/7.png') self.can7.create_image(0, 0, image=img7, anchor=NW) #--------------------------------------------------------------------------------- self.can8 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can8.grid(row=10, column=8) img8 = PhotoImage(file='cut_images/8.png') self.can8.create_image(0, 0, image=img8, anchor=NW) #--------------------------------------------------------------------------------- self.can9 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can9.grid(row=10, column=9) img9 = PhotoImage(file='cut_images/9.png') self.can9.create_image(0, 0, image=img9, anchor=NW) #--------------------------------------------------------------------------------- self.can10 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can10.grid(row=10, column=10) img10 = PhotoImage(file='cut_images/10.png') self.can10.create_image(0, 0, image=img10, anchor=NW) #--------------------------------------------------------------------------------- self.can11 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can11.grid(row=9, column=10) img11 = PhotoImage(file='cut_images/11.png') self.can11.create_image(0, 0, image=img11, anchor=NW) #--------------------------------------------------------------------------------- self.can12 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can12.grid(row=9, column=9) img12 = PhotoImage(file='cut_images/12.png') self.can12.create_image(0, 0, image=img12, anchor=NW) #--------------------------------------------------------------------------------- self.can13 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can13.grid(row=9, column=8) img13 = PhotoImage(file='cut_images/13.png') self.can13.create_image(0, 0, image=img13, anchor=NW) #--------------------------------------------------------------------------------- self.can14 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can14.grid(row=9, column=7) img14 = PhotoImage(file='cut_images/14.png') self.can14.create_image(0, 0, image=img14, anchor=NW) #--------------------------------------------------------------------------------- self.can15 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can15.grid(row=9, column=6) img15 = PhotoImage(file='cut_images/15.png') self.can15.create_image(0, 0, image=img15, anchor=NW) #--------------------------------------------------------------------------------- self.can16 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can16.grid(row=9, column=5) img16 = PhotoImage(file='cut_images/16.png') self.can16.create_image(0, 0, image=img16, anchor=NW) #--------------------------------------------------------------------------------- self.can17 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can17.grid(row=9, column=4) img17 = PhotoImage(file='cut_images/17.png') self.can17.create_image(0, 0, image=img17, anchor=NW) #--------------------------------------------------------------------------------- self.can18 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can18.grid(row=9, column=3) img18 = PhotoImage(file='cut_images/18.png') self.can18.create_image(0, 0, image=img18, anchor=NW) #--------------------------------------------------------------------------------- self.can19 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can19.grid(row=9, column=2) img19 = PhotoImage(file='cut_images/19.png') self.can19.create_image(0, 0, image=img19, anchor=NW) #--------------------------------------------------------------------------------- self.can20 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can20.grid(row=9, column=1) img20 = PhotoImage(file='cut_images/20.png') self.can20.create_image(0, 0, image=img20, anchor=NW) #--------------------------------------------------------------------------------- self.can21 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can21.grid(row=8, column=1) img21 = PhotoImage(file='cut_images/21.png') self.can21.create_image(0, 0, image=img21, anchor=NW) #--------------------------------------------------------------------------------- self.can22 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can22.grid(row=8, column=2) img22 = PhotoImage(file='cut_images/22.png') self.can22.create_image(0, 0, image=img22, anchor=NW) #--------------------------------------------------------------------------------- self.can23 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can23.grid(row=8, column=3) img23 = PhotoImage(file='cut_images/23.png') self.can23.create_image(0, 0, image=img23, anchor=NW) #--------------------------------------------------------------------------------- self.can24 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can24.grid(row=8, column=4) img24 = PhotoImage(file='cut_images/24.png') self.can24.create_image(0, 0, image=img24, anchor=NW) #--------------------------------------------------------------------------------- self.can25 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can25.grid(row=8, column=5) img25 = PhotoImage(file='cut_images/25.png') self.can25.create_image(0, 0, image=img25, anchor=NW) #--------------------------------------------------------------------------------- self.can26 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can26.grid(row=8, column=6) img26 = PhotoImage(file='cut_images/26.png') self.can26.create_image(0, 0, image=img26, anchor=NW) #--------------------------------------------------------------------------------- self.can27 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can27.grid(row=8, column=7) img27 = PhotoImage(file='cut_images/27.png') self.can27.create_image(0, 0, image=img27, anchor=NW) #--------------------------------------------------------------------------------- self.can28 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can28.grid(row=8, column=8) img28 = PhotoImage(file='cut_images/28.png') self.can28.create_image(0, 0, image=img28, anchor=NW) #--------------------------------------------------------------------------------- self.can29 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can29.grid(row=8, column=9) img29 = PhotoImage(file='cut_images/29.png') self.can29.create_image(0, 0, image=img29, anchor=NW) #--------------------------------------------------------------------------------- self.can30 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can30.grid(row=8, column=10) img30 = PhotoImage(file='cut_images/30.png') self.can30.create_image(0, 0, image=img30, anchor=NW) #--------------------------------------------------------------------------------- self.can31 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can31.grid(row=7, column=10) img31 = PhotoImage(file='cut_images/31.png') self.can31.create_image(0, 0, image=img31, anchor=NW) #--------------------------------------------------------------------------------- self.can32 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can32.grid(row=7, column=9) img32 = PhotoImage(file='cut_images/32.png') self.can32.create_image(0, 0, image=img32, anchor=NW) #--------------------------------------------------------------------------------- self.can33 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can33.grid(row=7, column=8) img33 = PhotoImage(file='cut_images/33.png') self.can33.create_image(0, 0, image=img33, anchor=NW) #--------------------------------------------------------------------------------- self.can34 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can34.grid(row=7, column=7) img34 = PhotoImage(file='cut_images/34.png') self.can34.create_image(0, 0, image=img34, anchor=NW) #--------------------------------------------------------------------------------- self.can35 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can35.grid(row=7, column=6) img35 = PhotoImage(file='cut_images/35.png') self.can35.create_image(0, 0, image=img35, anchor=NW) #--------------------------------------------------------------------------------- self.can36 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can36.grid(row=7, column=5) img36 = PhotoImage(file='cut_images/36.png') self.can36.create_image(0, 0, image=img36, anchor=NW) #--------------------------------------------------------------------------------- self.can37 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can37.grid(row=7, column=4) img37 = PhotoImage(file='cut_images/37.png') self.can37.create_image(0, 0, image=img37, anchor=NW) #--------------------------------------------------------------------------------- self.can38 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can38.grid(row=7, column=3) img38 = PhotoImage(file='cut_images/38.png') self.can38.create_image(0, 0, image=img38, anchor=NW) #--------------------------------------------------------------------------------- self.can39 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can39.grid(row=7, column=2) img39 = PhotoImage(file='cut_images/39.png') self.can39.create_image(0, 0, image=img39, anchor=NW) #--------------------------------------------------------------------------------- self.can40 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can40.grid(row=7, column=1) img40 = PhotoImage(file='cut_images/40.png') self.can40.create_image(0, 0, image=img40, anchor=NW) #--------------------------------------------------------------------------------- self.can41 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can41.grid(row=6, column=1) img41 = PhotoImage(file='cut_images/41.png') self.can41.create_image(0, 0, image=img41, anchor=NW) #--------------------------------------------------------------------------------- self.can42 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can42.grid(row=6, column=2) img42 = PhotoImage(file='cut_images/42.png') self.can42.create_image(0, 0, image=img42, anchor=NW) #--------------------------------------------------------------------------------- self.can43 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can43.grid(row=6, column=3) img43 = PhotoImage(file='cut_images/43.png') self.can43.create_image(0, 0, image=img43, anchor=NW) #--------------------------------------------------------------------------------- self.can44 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can44.grid(row=6, column=4) img44 = PhotoImage(file='cut_images/44.png') self.can44.create_image(0, 0, image=img44, anchor=NW) #--------------------------------------------------------------------------------- self.can45 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can45.grid(row=6, column=5) img45 = PhotoImage(file='cut_images/45.png') self.can45.create_image(0, 0, image=img45, anchor=NW) #--------------------------------------------------------------------------------- self.can46 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can46.grid(row=6, column=6) img46 = PhotoImage(file='cut_images/46.png') self.can46.create_image(0, 0, image=img46, anchor=NW) #--------------------------------------------------------------------------------- self.can47 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can47.grid(row=6, column=7) img47 = PhotoImage(file='cut_images/47.png') self.can47.create_image(0, 0, image=img47, anchor=NW) #--------------------------------------------------------------------------------- self.can48 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can48.grid(row=6, column=8) img48 = PhotoImage(file='cut_images/48.png') self.can48.create_image(0, 0, image=img48, anchor=NW) #--------------------------------------------------------------------------------- self.can49 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can49.grid(row=6, column=9) img49 = PhotoImage(file='cut_images/49.png') self.can49.create_image(0, 0, image=img49, anchor=NW) #--------------------------------------------------------------------------------- self.can50 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can50.grid(row=6, column=10) img50 = PhotoImage(file='cut_images/50.png') self.can50.create_image(0, 0, image=img50, anchor=NW) #--------------------------------------------------------------------------------- self.can51 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can51.grid(row=5, column=10) img51 = PhotoImage(file='cut_images/51.png') self.can51.create_image(0, 0, image=img51, anchor=NW) #--------------------------------------------------------------------------------- self.can52 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can52.grid(row=5, column=9) img52 = PhotoImage(file='cut_images/52.png') self.can52.create_image(0, 0, image=img52, anchor=NW) #--------------------------------------------------------------------------------- self.can53 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can53.grid(row=5, column=8) img53 = PhotoImage(file='cut_images/53.png') self.can53.create_image(0, 0, image=img53, anchor=NW) #--------------------------------------------------------------------------------- self.can54 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can54.grid(row=5, column=7) img54 = PhotoImage(file='cut_images/54.png') self.can54.create_image(0, 0, image=img54, anchor=NW) #--------------------------------------------------------------------------------- self.can55 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can55.grid(row=5, column=6) img55 = PhotoImage(file='cut_images/55.png') self.can55.create_image(0, 0, image=img55, anchor=NW) #--------------------------------------------------------------------------------- self.can56 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can56.grid(row=5, column=5) img56 = PhotoImage(file='cut_images/56.png') self.can56.create_image(0, 0, image=img56, anchor=NW) #--------------------------------------------------------------------------------- self.can57 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can57.grid(row=5, column=4) img57 = PhotoImage(file='cut_images/57.png') self.can57.create_image(0, 0, image=img57, anchor=NW) #--------------------------------------------------------------------------------- self.can58 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can58.grid(row=5, column=3) img58 = PhotoImage(file='cut_images/58.png') self.can58.create_image(0, 0, image=img58, anchor=NW) #--------------------------------------------------------------------------------- self.can59 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can59.grid(row=5, column=2) img59 = PhotoImage(file='cut_images/59.png') self.can59.create_image(0, 0, image=img59, anchor=NW) #--------------------------------------------------------------------------------- self.can60 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can60.grid(row=5, column=1) img60 = PhotoImage(file='cut_images/60.png') self.can60.create_image(0, 0, image=img60, anchor=NW) #--------------------------------------------------------------------------------- self.can61 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can61.grid(row=4, column=1) img61 = PhotoImage(file='cut_images/61.png') self.can61.create_image(0, 0, image=img61, anchor=NW) #--------------------------------------------------------------------------------- self.can62 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can62.grid(row=4, column=2) img62 = PhotoImage(file='cut_images/62.png') self.can62.create_image(0, 0, image=img62, anchor=NW) #--------------------------------------------------------------------------------- self.can63 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can63.grid(row=4, column=3) img63 = PhotoImage(file='cut_images/63.png') self.can63.create_image(0, 0, image=img63, anchor=NW) #--------------------------------------------------------------------------------- self.can64 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can64.grid(row=4, column=4) img64 = PhotoImage(file='cut_images/64.png') self.can64.create_image(0, 0, image=img64, anchor=NW) #--------------------------------------------------------------------------------- self.can65 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can65.grid(row=4, column=5) img65 = PhotoImage(file='cut_images/65.png') self.can65.create_image(0, 0, image=img65, anchor=NW) #--------------------------------------------------------------------------------- self.can66 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can66.grid(row=4, column=6) img66 = PhotoImage(file='cut_images/66.png') self.can66.create_image(0, 0, image=img66, anchor=NW) #--------------------------------------------------------------------------------- self.can67 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can67.grid(row=4, column=7) img67 = PhotoImage(file='cut_images/67.png') self.can67.create_image(0, 0, image=img67, anchor=NW) #--------------------------------------------------------------------------------- self.can68 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can68.grid(row=4, column=8) img68 = PhotoImage(file='cut_images/68.png') self.can68.create_image(0, 0, image=img68, anchor=NW) #--------------------------------------------------------------------------------- self.can69 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can69.grid(row=4, column=9) img69 = PhotoImage(file='cut_images/69.png') self.can69.create_image(0, 0, image=img69, anchor=NW) #--------------------------------------------------------------------------------- self.can70 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can70.grid(row=4, column=10) img70 = PhotoImage(file='cut_images/70.png') self.can70.create_image(0, 0, image=img70, anchor=NW) # --------------------------------------------------------------------------------- self.can71 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can71.grid(row=3, column=10) img71 = PhotoImage(file='cut_images/71.png') self.can71.create_image(0, 0, image=img71, anchor=NW) #--------------------------------------------------------------------------------- self.can72 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can72.grid(row=3, column=9) img72 = PhotoImage(file='cut_images/72.png') self.can72.create_image(0, 0, image=img72, anchor=NW) #--------------------------------------------------------------------------------- self.can73 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can73.grid(row=3, column=8) img73 = PhotoImage(file='cut_images/73.png') self.can73.create_image(0, 0, image=img73, anchor=NW) # --------------------------------------------------------------------------------- self.can74 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can74.grid(row=3, column=7) img74 = PhotoImage(file='cut_images/74.png') self.can74.create_image(0, 0, image=img74, anchor=NW) #--------------------------------------------------------------------------------- self.can75 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can75.grid(row=3, column=6) img75 = PhotoImage(file='cut_images/75.png') self.can75.create_image(0, 0, image=img75, anchor=NW) #--------------------------------------------------------------------------------- self.can76 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can76.grid(row=3, column=5) img76 = PhotoImage(file='cut_images/76.png') self.can76.create_image(0, 0, image=img76, anchor=NW) # --------------------------------------------------------------------------------- self.can77 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can77.grid(row=3, column=4) img77 = PhotoImage(file='cut_images/77.png') self.can77.create_image(0, 0, image=img77, anchor=NW) #--------------------------------------------------------------------------------- self.can78 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can78.grid(row=3, column=3) img78 = PhotoImage(file='cut_images/78.png') self.can78.create_image(0, 0, image=img78, anchor=NW) #--------------------------------------------------------------------------------- self.can79 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can79.grid(row=3, column=2) img79 = PhotoImage(file='cut_images/79.png') self.can79.create_image(0, 0, image=img79, anchor=NW) # --------------------------------------------------------------------------------- self.can80 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can80.grid(row=3, column=1) img80 = PhotoImage(file='cut_images/80.png') self.can80.create_image(0, 0, image=img80, anchor=NW) #--------------------------------------------------------------------------------- self.can81 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can81.grid(row=2, column=1) img81 = PhotoImage(file='cut_images/81.png') self.can81.create_image(0, 0, image=img81, anchor=NW) #--------------------------------------------------------------------------------- self.can82 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can82.grid(row=2, column=2) img82 = PhotoImage(file='cut_images/82.png') self.can82.create_image(0, 0, image=img82, anchor=NW) # --------------------------------------------------------------------------------- self.can83 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can83.grid(row=2, column=3) img83 = PhotoImage(file='cut_images/83.png') self.can83.create_image(0, 0, image=img83, anchor=NW) # --------------------------------------------------------------------------------- self.can84 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can84.grid(row=2, column=4) img84 = PhotoImage(file='cut_images/84.png') self.can84.create_image(0, 0, image=img84, anchor=NW) # --------------------------------------------------------------------------------- self.can85 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can85.grid(row=2, column=5) img85 = PhotoImage(file='cut_images/85.png') self.can85.create_image(0, 0, image=img85, anchor=NW) # --------------------------------------------------------------------------------- self.can86 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can86.grid(row=2, column=6) img86 = PhotoImage(file='cut_images/86.png') self.can86.create_image(0, 0, image=img86, anchor=NW) # --------------------------------------------------------------------------------- self.can87 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can87.grid(row=2, column=7) img87 = PhotoImage(file='cut_images/87.png') self.can87.create_image(0, 0, image=img87, anchor=NW) # --------------------------------------------------------------------------------- self.can88 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can88.grid(row=2, column=8) img88 = PhotoImage(file='cut_images/88.png') self.can88.create_image(0, 0, image=img88, anchor=NW) # --------------------------------------------------------------------------------- self.can89 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can89.grid(row=2, column=9) img89 = PhotoImage(file='cut_images/89.png') self.can89.create_image(0, 0, image=img89, anchor=NW) # --------------------------------------------------------------------------------- self.can90 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can90.grid(row=2, column=10) img90 = PhotoImage(file='cut_images/90.png') self.can90.create_image(0, 0, image=img90, anchor=NW) # --------------------------------------------------------------------------------- self.can91 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can91.grid(row=1, column=10) img91 = PhotoImage(file='cut_images/91.png') self.can91.create_image(0, 0, image=img91, anchor=NW) # --------------------------------------------------------------------------------- self.can92 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can92.grid(row=1, column=9) img92 = PhotoImage(file='cut_images/92.png') self.can92.create_image(0, 0, image=img92, anchor=NW) # --------------------------------------------------------------------------------- self.can93 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can93.grid(row=1, column=8) img93 = PhotoImage(file='cut_images/93.png') self.can93.create_image(0, 0, image=img93, anchor=NW) # --------------------------------------------------------------------------------- self.can94 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can94.grid(row=1, column=7) img94 = PhotoImage(file='cut_images/94.png') self.can94.create_image(0, 0, image=img94, anchor=NW) # --------------------------------------------------------------------------------- self.can95 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can95.grid(row=1, column=6) img95 = PhotoImage(file='cut_images/95.png') self.can95.create_image(0, 0, image=img95, anchor=NW) # --------------------------------------------------------------------------------- self.can96 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can96.grid(row=1, column=5) img96 = PhotoImage(file='cut_images/96.png') self.can96.create_image(0, 0, image=img96, anchor=NW) # --------------------------------------------------------------------------------- self.can97 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can97.grid(row=1, column=4) img97 = PhotoImage(file='cut_images/97.png') self.can97.create_image(0, 0, image=img97, anchor=NW) # --------------------------------------------------------------------------------- self.can98 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can98.grid(row=1, column=3) img98 = PhotoImage(file='cut_images/98.png') self.can98.create_image(0, 0, image=img98, anchor=NW) # --------------------------------------------------------------------------------- self.can99 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can99.grid(row=1, column=2) img99 = PhotoImage(file='cut_images/99.png') self.can99.create_image(0, 0, image=img99, anchor=NW) # --------------------------------------------------------------------------------- self.can100 = Canvas(left, height=img0.size[0], width=img0.size[0]) self.can100.grid(row=1, column=1) img100 = PhotoImage(file='cut_images/100.png') self.can100.create_image(0, 0, image=img100, anchor=NW) self.can_list = [ "", self.can1, self.can2, self.can3, self.can4, self.can5, self.can6, self.can7, self.can8, self.can9, self.can10, self.can11, self.can12, self.can13, self.can14, self.can15, self.can16, self.can17, self.can18, self.can19, self.can20, self.can21, self.can22, self.can23, self.can24, self.can25, self.can26, self.can27, self.can28, self.can29, self.can30, self.can31, self.can32, self.can33, self.can34, self.can35, self.can36, self.can37, self.can38, self.can39, self.can40, self.can41, self.can42, self.can43, self.can44, self.can45, self.can46, self.can47, self.can48, self.can49, self.can50, self.can51, self.can52, self.can53, self.can54, self.can55, self.can56, self.can57, self.can58, self.can59, self.can60, self.can61, self.can62, self.can63, self.can64, self.can65, self.can66, self.can67, self.can68, self.can69, self.can70, self.can71, self.can72, self.can73, self.can74, self.can75, self.can76, self.can77, self.can78, self.can79, self.can80, self.can81, self.can82, self.can83, self.can84, self.can85, self.can86, self.can87, self.can88, self.can89, self.can90, self.can91, self.can92, self.can93, self.can94, self.can95, self.can96, self.can97, self.can98, self.can99, self.can100 ] root.mainloop()
t2 = 1 lezer2 = c.create_rectangle(wx - spx - fx, wy / 2 - ty / 2, wx - spx - fx - tx, wy / 2 + ty / 2, fill='red') for _ in range(200): c.move(lezer2, -6, 0) window.update() t2 = 1 sleep(0.01) c.delete(lezer2) t2 = 0 window = Tk() window.title('シューティングゲーム') c = Canvas(window, height=wy, width=wx, bg='blue') c.pack() # while True: ship = c.create_polygon(spx + fx, wy / 2, spx + fx - fh, wy / 2 - fy / 2, spx, wy / 2, spx + fx - fh, wy / 2 + fy / 2, fill='yellow')
global server_socket # set new ip/port if it's different from default HOST = ip_e.get("1.0", "end-1c") PORT = int(prt_e.get("1.0", "end-1c")) msg_list.insert(END, ("Server << " + HOST + " >> is connected")) ############################################################## ''' + SERVER GUI: Using Tkinter ''' ############################################################## # set tkinter to display GUI root = Tk() root.title("SERVER T.I.M | Tiger Instant Messager") root.resizable(width=False, height=False) root.geometry('550x650') ############################################################## #----------------------------header--------------------------# header_frame = Frame(root) # tiger image for header photo_1 = PhotoImage(file="icon_TIM.png") lab_1 = Label(root, image=photo_1) lab_1.pack() # label for connection information lab_2 = Label( header_frame,
class Tetris(): SHAPES = ([(0, 0), (1, 0), (0, 1), (1, 1)], # Square [(0, 0), (1, 0), (2, 0), (3, 0)], # Line [(2, 0), (0, 1), (1, 1), (2, 1)], # Right L [(0, 0), (0, 1), (1, 1), (2, 1)], # Left L [(0, 1), (1, 1), (1, 0), (2, 0)], # Right Z [(0, 0), (1, 0), (1, 1), (2, 1)], # Left Z [(1, 0), (0, 1), (1, 1), (2, 1)]) # T BOX_SIZE = 20 GAME_WIDTH = 300 GAME_HEIGHT = 500 GAME_START_POINT = GAME_WIDTH / 2 / BOX_SIZE * BOX_SIZE - BOX_SIZE def __init__(self, predictable = False): self._level = 1 self._score = 0 self._blockcount = 0 self.speed = 500 self.predictable = predictable self.root = Tk() self.root.geometry("500x550") self.root.title('Tetris') self.root.bind("<Key>", self.game_control) self.__game_canvas() self.__level_score_label() self.__next_piece_canvas() def game_control(self, event): if event.char in ["a", "A", "\uf702"]: self.current_piece.move((-1, 0)) self.update_predict() elif event.char in ["d", "D", "\uf703"]: self.current_piece.move((1, 0)) self.update_predict() elif event.char in ["s", "S", "\uf701"]: self.hard_drop() elif event.char in ["w", "W", "\uf700"]: self.current_piece.rotate() self.update_predict() def new_game(self): self.level = 1 self.score = 0 self.blockcount = 0 self.speed = 500 self.canvas.delete("all") self.next_canvas.delete("all") self.__draw_canvas_frame() self.__draw_next_canvas_frame() self.current_piece = None self.next_piece = None self.game_board = [[0] * ((Tetris.GAME_WIDTH - 20) // Tetris.BOX_SIZE)\ for _ in range(Tetris.GAME_HEIGHT // Tetris.BOX_SIZE)] self.update_piece() def update_piece(self): if not self.next_piece: self.next_piece = Piece(self.next_canvas, (20,20)) self.current_piece = Piece(self.canvas, (Tetris.GAME_START_POINT, 0), self.next_piece.shape) self.next_canvas.delete("all") self.__draw_next_canvas_frame() self.next_piece = Piece(self.next_canvas, (20,20)) self.update_predict() def start(self): self.new_game() self.root.after(self.speed, None) self.drop() self.root.mainloop() def drop(self): if not self.current_piece.move((0,1)): self.current_piece.remove_predicts() self.completed_lines() self.game_board = self.canvas.game_board() self.update_piece() if self.is_game_over(): return else: self._blockcount += 1 self.score += 1 self.root.after(self.speed, self.drop) def hard_drop(self): self.current_piece.move(self.current_piece.predict_movement(self.game_board)) def update_predict(self): if self.predictable: self.current_piece.predict_drop(self.game_board) def update_status(self): self.status_var.set(f"Level: {self.level}, Score: {self.score}") self.status.update() def is_game_over(self): if not self.current_piece.move((0,1)): self.play_again_btn = Button(self.root, text="Play Again", command=self.play_again) self.quit_btn = Button(self.root, text="Quit", command=self.quit) self.play_again_btn.place(x = Tetris.GAME_WIDTH + 10, y = 200, width=100, height=25) self.quit_btn.place(x = Tetris.GAME_WIDTH + 10, y = 300, width=100, height=25) return True return False def play_again(self): self.play_again_btn.destroy() self.quit_btn.destroy() self.start() def quit(self): self.root.quit() def completed_lines(self): y_coords = [self.canvas.coords(box)[3] for box in self.current_piece.boxes] completed_line = self.canvas.completed_lines(y_coords) if completed_line == 1: self.score += 400 elif completed_line == 2: self.score += 1000 elif completed_line == 3: self.score += 3000 elif completed_line >= 4: self.score += 12000 def __game_canvas(self): self.canvas = GameCanvas(self.root, width = Tetris.GAME_WIDTH, height = Tetris.GAME_HEIGHT) self.canvas.pack(padx=5 , pady=10, side=LEFT) def __level_score_label(self): self.status_var = StringVar() self.status = Label(self.root, textvariable=self.status_var, font=("Helvetica", 10, "bold")) #self.status.place(x = Tetris.GAME_WIDTH + 10, y = 100, width=100, height=25) self.status.pack() def __next_piece_canvas(self): self.next_canvas = Canvas(self.root, width = 100, height = 100) self.next_canvas.pack(padx=5 , pady=10) def __draw_canvas_frame(self): self.canvas.create_line(10, 0, 10, self.GAME_HEIGHT, fill = "red", tags = "line") self.canvas.create_line(self.GAME_WIDTH-10, 0, self.GAME_WIDTH-10, self.GAME_HEIGHT, fill = "red", tags = "line") self.canvas.create_line(10, self.GAME_HEIGHT, self.GAME_WIDTH-10, self.GAME_HEIGHT, fill = "red", tags = "line") def __draw_next_canvas_frame(self): self.next_canvas.create_rectangle(10, 10, 90, 90, tags="frame") #set & get def __get_level(self): return self._level def __set_level(self, level): self.speed = 500 - (level - 1) * 25 self._level = level self.update_status() def __get_score(self): return self._score def __set_score(self, score): self._score = score self.update_status() def __get_blockcount(self): return self._blockcount def __set_blockcount(self, blockcount): self.level = blockcount // 5 + 1 self._blockcount = blockcount level = property(__get_level, __set_level) score = property(__get_score, __set_score) blockcount = property(__get_blockcount, __set_blockcount)
from tkinter import messagebox, simpledialog, Tk import sys import random if __name__ == '__main__': window = Tk() window.withdraw() # 1. Change this line to give you a random number between 1 - 100. random_num = random.randint(1, 10) # 2. Print out the random variable above # 3. Code a for loop to run steps 4-10, 10 times # 4. Ask the user for a guess using a pop-up window, and save their response # 5. If the guess is correct # 6. Win. Use 'sys.exit(0)' to end the program # 7. if the guess is high # 8. Tell them it's too high # 9. Else if the guess is low # 10. Tell them it's too low #11. Outside of the loop, tell the user they lost window.mainloop()
# coding = <utf-8> """ 버튼 위젯 (ref) https://youtu.be/bKPIcoou9N8?t=526 """ import os import os.path as osp from tkinter import Tk, Button, PhotoImage root = Tk() root.title("My GUI") btn1 = Button(root, text="버튼1") # 버튼 객체 초기화 btn1.pack() # mainloop() 에 버튼이 표출되도록 함 btn2 = Button(root, padx=5, pady=10, text='버튼2') # 디폴트 버튼 박스 크기에서 패딩(padding) btn2.pack() btn3 = Button(root, padx=10, pady=5, text='버튼3') btn3.pack() btn4 = Button(root, width=10, height=3, text='버튼4') # 고정 박스 크기를 직접 설정 btn4.pack() btn5 = Button(root, fg='red', bg="yellow", text='버튼5') # foreground, background 색상 btn5.pack() img_path = osp.join(os.getcwd(), 'steps', 'images', 'button.png') # 이미지로 버튼 만들기 photo = PhotoImage(file=img_path)
from tkinter import Tk, simpledialog, messagebox root = Tk() root.withdraw() the_world = {} def read_data(): with open('capital_city.txt') as file: for line in file: line = line.rstrip('\n') country, city = line.split(':') the_world[country] = city def write_data(country_name, city_name): with open('capital_city.txt', 'a') as file: file.write('\n' + country_name + ':' + city_name) read_data() while True: query_country = simpledialog.askstring( 'Ask the Expert!', 'Enter the country name to get capital city') if query_country: query_country = query_country.capitalize() else: break if query_country in the_world: result = the_world[query_country] messagebox.showinfo(
from tkinter import Tk, Entry, Label from pyautogui import click, moveTo from time import sleep def callback(event): global k, entry if entry.get()=="hello": k=True def on_closing(): click(675, 420) moveTo(675, 420) root.attributes("-fullscreen", True) root.protocol("WM_DELETE_WINDOW", on_closing) root.update() root.bind('<Control-KeyPress-c>', callback) root = Tk() root.title("Locker") root.attributes("-fullscreen", True) entry = Entry(root, font = 1) entry.place(width = 150, height = 50, x = 600, y = 400) label0 = Label(root, text = "Locker", font = 1) label0.grid(row = 0, column = 0) label1 = Label(root, text = "Write the Password and Press Ctrl+C", font="Arial 20") label1.place(x = 470, y = 300) root.update() sleep(0.2) click(675, 420) k = False while k != True: on_closing()
current_state = c.itemcget(pupil_left, 'state') new_state = NORMAL if current_state == HIDDEN else HIDDEN c.itemconfigure(pupil_left, state=new_state) c.itemconfigure(pupil_right, state=new_state) c.itemconfigure(eye_left, fill=new_color) c.itemconfigure(eye_right, fill=new_color) def blink(): toggle_eyes() root.after(250, toggle_eyes) root.after(3000, blink) root = Tk() c = Canvas(root, width=400, height=400) c.configure(bg='dark blue', highlightthickness=0) c.body_color = 'SkyBlue1' body = c.create_oval(35, 20, 365, 350, outline=c.body_color, fill=c.body_color) ear_left = c.create_polygon(75, 80, 75, 10, 165, 70, outline=c.body_color, fill=c.body_color) ear_right = c.create_polygon( 255, 45, 325, 10, 320, 70, outline=c.body_color, fill=c.body_color) foot_left = c.create_oval(
class CIDRCalcGUI: def __init__(self): self.subnet = Subnet() self.cidr = Tk() self.cidr.wm_title('CIDR Calculator') self.cidr_from_netmask = LabelFrame( self.cidr, text='CIDR: Network Address & Netmask') self.net_address_label = Label(self.cidr_from_netmask, text='Network Address:') self.netmask_label = Label(self.cidr_from_netmask, text='Netmask:') self.net_address_entry = Entry(self.cidr_from_netmask, width=25) self.netmask_entry = Entry(self.cidr_from_netmask, width=25) self.cidr_from_ip_range = LabelFrame( self.cidr, text='CIDR: Network Address & Assignable IP Range') self.net_address_label2 = Label(self.cidr_from_ip_range, text='Network Address:') self.ip_range_label = Label(self.cidr_from_ip_range, text='Assignable IP Range:') self.net_address_entry2 = Entry(self.cidr_from_ip_range, width=25) self.ip_range_entry = Entry(self.cidr_from_ip_range, width=25) self.learning_steps = LabelFrame(self.cidr, text='Learning Steps') self.calculate = Button(self.cidr_from_netmask, text='Calculate', command=lambda: self.get_cidr_from_netmask()) self.calculate2 = Button(self.cidr_from_ip_range, text='Calculate', command=lambda: self.get_cidr_from_ip_range()) self.cidr_from_netmask.grid(row=0) self.cidr_from_ip_range.grid(row=1) self.learning_steps.grid(row=2, sticky='W') self.net_address_label.grid(row=0, column=0, sticky='W') self.net_address_entry.grid(row=1, column=0) self.netmask_label.grid(row=0, column=1, sticky='W') self.netmask_entry.grid(row=1, column=1) self.calculate.grid(row=1, column=2) self.net_address_label2.grid(row=0, column=0, sticky='W') self.net_address_entry2.grid(row=1, column=0) self.ip_range_label.grid(row=0, column=1, sticky='W') self.ip_range_entry.grid(row=1, column=1) self.calculate2.grid(row=1, column=2) # self.cidr.mainloop() def get_cidr_from_netmask(self): if self.subnet.cidr_address != '': self.clear_and_reset() else: self.subnet.network_address = self.net_address_entry.get() self.subnet.netmask = self.netmask_entry.get() if self.subnet.network_address != '' and self.subnet.netmask != '' and self.subnet.verify_variables( ): self.subnet.calculate_cidr_from_netmask() steps = self.subnet.cidr_address_steps step1 = Label(self.learning_steps, text='Step 1:') network = Label(self.learning_steps, text='Network Address: {}'.format( self.subnet.network_address)) netmask = Label(self.learning_steps, text='NetMask: {}'.format(self.subnet.netmask)) step2 = Label(self.learning_steps, text='Step 2:') binary = Label(self.learning_steps, text='Netmask Binary: {}'.format( steps[0]['Netmask Binary'])) step3 = Label(self.learning_steps, text='Step 3:') count = Label(self.learning_steps, text="(Count 0's from Step 2)") cidr = Label(self.learning_steps, text='CIDR: {}'.format(steps[1]['CIDR'])) step4 = Label(self.learning_steps, text='Step 4:') cidr_address = Label(self.learning_steps, text='CIDR Address: {}'.format( self.subnet.cidr_address)) step1.grid(row=0, column=0, sticky='W') network.grid(row=0, column=1, sticky='W') netmask.grid(row=0, column=2, sticky='W') step2.grid(row=1, column=0, sticky='W') binary.grid(row=1, column=1, columnspan=2, sticky='W') step3.grid(row=2, column=0, sticky='W') count.grid(row=2, column=1, sticky='W') cidr.grid(row=2, column=2, sticky='W') step4.grid(row=3, column=0, sticky='W') cidr_address.grid(row=3, column=1, sticky='W') else: self.clear_and_reset() HelpGUI() def get_cidr_from_ip_range(self): if self.subnet.cidr_address != '': self.clear_and_reset() else: self.subnet.network_address = self.net_address_entry2.get() self.subnet.ip_range = self.ip_range_entry.get() if self.subnet.network_address != '' and self.subnet.ip_range != '' and self.subnet.verify_variables( ): self.subnet.calculate_cidr_from_ip_range() steps = self.subnet.cidr_address_steps step1 = Label(self.learning_steps, text='Step 1:') network = Label(self.learning_steps, text='Network Address: {}'.format( self.subnet.network_address)) ip_range = Label(self.learning_steps, text='Assignable IP Range: {}'.format( self.subnet.ip_range)) step2 = Label(self.learning_steps, text='Step 2:') front = Label(self.learning_steps, text='Front: {}'.format(steps[0]['Front'])) back = Label(self.learning_steps, text=' Back: {}'.format(steps[0]['Back'])) step3 = Label(self.learning_steps, text='Step 3:') comparison = Label(self.learning_steps, text='Comparison: {}'.format( steps[1]['Comparison'])) step4 = Label(self.learning_steps, text='Step 4:') cidr = Label(self.learning_steps, text='CIDR: {}'.format(steps[2]['CIDR'])) step5 = Label(self.learning_steps, text='Step 5:') cidr_address = Label(self.learning_steps, text='CIDR Address: {}'.format( self.subnet.cidr_address)) step1.grid(row=0, column=0, sticky='W') network.grid(row=0, column=1, sticky='W') ip_range.grid(row=1, column=1, sticky='W') step2.grid(row=2, column=0, sticky='W') front.grid(row=2, column=1, sticky='W') back.grid(row=3, column=1, sticky='W') step3.grid(row=4, column=0, sticky='W') comparison.grid(row=4, column=1, columnspan=2, sticky='W') step4.grid(row=5, column=0, sticky='W') cidr.grid(row=5, column=1, sticky='W') step5.grid(row=6, column=0, sticky='W') cidr_address.grid(row=6, column=1, sticky='W') else: self.clear_and_reset() HelpGUI() def clear_and_reset(self): self.net_address_entry.delete(0, 'end') self.netmask_entry.delete(0, 'end') self.net_address_entry2.delete(0, 'end') self.ip_range_entry.delete(0, 'end') self.subnet.reset_variables() for child in self.learning_steps.winfo_children(): child.destroy() def generate_main(self): self.cidr.mainloop()
class Example(): __file = None root = Tk("Text Editor") root.geometry("250x150+300+300") __thisTextArea = Text(root) def __openFile(self): self.__file = filedialog.askopenfilename(defaultextension=".py", filetypes=[ ("All Files", "*.*"), ("Text Documents", "*.txt"), ("Python Files", "*.py") ]) if self.__file == "": self.__file = None else: self.root.title(os.path.basename(self.__file) + " - Notepad") self.__thisTextArea.delete(1.0, END) file = open(self.__file, "r") self.__thisTextArea.insert(1.0, file.read()) file.close() def __newFile(self): self.root.title("Untitled - Notepad") self.__file = None self.__thisTextArea.delete(1.0, END) def __saveFile(self): if self.__file == None: #save as new file self.__file = filedialog.asksaveasfilename( initialfile='Untitled.py', defaultextension=".py", filetypes=[("Python Files", "*.py"), ("All Files", "*.*"), ("Text Documents", "*.txt")]) if self.__file == "": self.__file = None else: # try to save the file file = open(self.__file, "w") file.write(self.__thisTextArea.get(1.0, END)) file.close() # change the window title self.root.title(os.path.basename(self.__file) + " - Notepad") else: file = open(self.__file, "w") file.write(self.__thisTextArea.get(1.0, END)) file.close() def __init__(self): super().__init__() self.initUI() def compiler(self): fname = open(self.__file, 'r') text_input = fname.readlines() for i in text_input: i = i[6:-2] try: exec(i) except ZeroDivisionError: print("not complied") sys.exit() lexer = cp.Lexer().get_lexer() codegen = cp.CodeGen() module = codegen.module builder = codegen.builder printf = codegen.printf for s in text_input: tokens = lexer.lex(s) pg = cp.Parser(module, builder, printf) pg.parse() parser = pg.get_parser() parser.parse(tokens) codegen.create_ir() qwerty = codegen.save_ir() with open('{}.ll'.format(self.__file[:-3:]), 'w') as output: output.write(str(qwerty)) x = '{}'.format(self.__file[:-3:]) cp.subprocess.call( ['llc', '-filetype=obj', '{}.ll'.format(self.__file[:-3:])]) cp.subprocess.call( ['clang', '{}.obj'.format(x), '-o', '{}.exe'.format(x)]) print('Compiled Successfully------------->>') def run(self): x = '{}'.format(self.__file[:-3:]) w = cp.subprocess.Popen(['{}.exe'.format(x)], stdout=cp.subprocess.PIPE) print(w.communicate()[0]) print('Run Successfully------------->>') def initUI(self): self.root.title("Text Editor") toolbar = Frame(self.root.master, bd=1, relief=RAISED) exitButton = Button(toolbar, text='Exit', relief=FLAT, command=self.root.destroy) newButton = Button(toolbar, text='New', relief=FLAT, command=self.__newFile) openButton = Button(toolbar, text='Open', relief=FLAT, command=self.__openFile) saveButton = Button(toolbar, text='Save', relief=FLAT, command=self.__saveFile) compileButton = Button(toolbar, text='Compile', relief=FLAT, command=self.compiler) runButton = Button(toolbar, text='Run', relief=FLAT, command=self.run) newButton.pack(side=LEFT, padx=2, pady=2) openButton.pack(side=LEFT, padx=2, pady=2) saveButton.pack(side=LEFT, padx=2, pady=2) compileButton.pack(side=LEFT, padx=2, pady=2) runButton.pack(side=LEFT, padx=2, pady=2) exitButton.pack(side=LEFT, padx=2, pady=2) toolbar.pack(side=TOP, fill=X) self.__thisTextArea.pack() def onExit(self): self.quit()
from os import close from tkinter import Tk, Label, Button, StringVar from tkinter import E, N, S, W import subprocess, time, os from tkinter import Toplevel from tkinter.constants import COMMAND, DISABLED top =Toplevel root = Tk() root.iconbitmap() class Installation: LABEL_TEXT = [ "Which Type of Package Manager are you using?" ] def __init__(self, master): self.master = master master.title("Installation Script") self.label_index = 0 self.label_text = StringVar() self.label_text.set(self.LABEL_TEXT[self.label_index]) self.label = Label(master, textvariable=self.label_text) self.label.bind("<Button-1>", self.cycle_label_text) self.label.grid(pady=10,padx=10) #****APT button**** self.APT_button = Button(master, text="APT", command=self.APT, bg='grey', font='white') self.APT_button.grid(row=3, column=0, sticky=W,pady=10,padx=10) #****Pacman button**** self.arch_button = Button(master, text="Pacman", command=self.arch, bg='blue', font='white')
try: md2html = Markdown() self.outputbox.set_html(md2html.convert(open(filename, 'r').read())) except Exception: mbox.showerror('Error opening file', 'The selected file cannot be opened !') def init_window(self): self.master.title('Mardown Viewer') self.pack(fill=tk.BOTH, expand=1) self.mainmenu = tk.Menu(self) self.filemenu = tk.Menu(self.mainmenu) self.filemenu.add_command(label='Open', command=self.openfile) self.filemenu.add_separator() self.filemenu.add_command(label='Exit', command=self.quit) self.mainmenu.add_cascade(label='File', menu=self.filemenu) self.master.config(menu=self.mainmenu) self.outputbox = HTMLLabel(self, width='1', background='white', html='<h1>Welcome</h1>') self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT) self.outputbox.fit_height() root = Tk() root.geometry('750x600') app = Window(master=root) app.mainloop()
from tkinter import Tk, Label, Button class MyFirstGUI: def __init__(self, master): self.master = master master.title("A simple GUI") master.geometry('400x200') self.label = Label(master, text="Welcome to Python class!") self.label.pack() # greet() is called when buttion is pressed self.greet_button = Button(master, text="Greet", command=self.greet) self.greet_button.pack() # Where is quit() defined? self.close_button = Button(master, text="Close", command=master.quit) # Use "pack" layout self.close_button.pack() # Event handler def greet(self): print("Greetings on console!") mainWindow = Tk() # Why not tkinter.Tk() ? my_gui = MyFirstGUI(mainWindow) mainWindow.mainloop()
def __init__(self): self.save_list = [] self._last_pointer_line = 0 self._whole_text = "" Tk.__init__(self) self._editor_frame = Text(master=self, bg='#2D3038', fg='white', height=25, width=131, wrap='none', undo=True) self._editor_frame.grid(row=1, column=2, columnspan=6) self._navigator = Frame(master=self, height=428, width=230) self._navigator.grid(row=1, column=0, columnspan=2) self._compile_button = Button(master=self, command=self._compile, text='Compile', width=16, height=1) self._compile_button.grid(row=0, column=0) self._save_button = Button(master=self, command=self._save, text='Save', width=16, height=1) self._save_button.grid(row=0, column=1, columnspan=2) self._save_as_button = Button(master=self, command=self._save_as, text='Save as', width=16, height=1) self._save_as_button.grid(row=0, column=3) self._open_button = Button(master=self, command=self._open, text='Open', width=16, height=1) self._open_button.grid(row=0, column=4) self._quit_button = Button(master=self, command=self.shutdown, text='Quit', width=16, height=1) self._quit_button.grid(row=0, column=6) self._newfile_button = Button(master=self, command=self._create_file, text="New", width=16, height=1) self._newfile_button.grid(row=0, column=5) self._output = Text(master=self, bg='#9FAEB3', height=12, width=80, fg='black') self._output.grid(row=2, column=0, columnspan=5) self._verbose = IntVar() self._verbosity_checkbutton = Checkbutton(master=self, variable=self._verbose, text='Verbose output') self._verbosity_checkbutton.grid(row=3, column=0) self._only_show_kombu_files = IntVar(self, 1) self._only_show_kombu_files_checkbutton = Checkbutton( master=self, variable=self._only_show_kombu_files, text='Only show kombu files', command=self.foo) self._only_show_kombu_files_checkbutton.grid(row=3, column=1, columnspan=2) self._compile_main = IntVar(self, 1) self._compile_main_checkbutton = Checkbutton( master=self, variable=self._compile_main, text='Always compile file main.kb') self._compile_main_checkbutton.grid(row=3, column=3, columnspan=2) self._test_zone = Text(master=self, bg='white', fg='black', height=12, width=80) self._test_zone.grid(row=2, column=5, columnspan=2) self._test_button = Button(master=self, command=self._test_code, text='Test', width=77, height=1) self._test_button.grid(row=3, column=5, columnspan=2) self._output_message = "Nothing to show" self._compiler_code = '!' self._compiler_properties = {} self._filepath = None self.bind_ctrls()
def main(): root = Tk() root.geometry("1000x600") app = Example() root.mainloop()
def setUpClass(cls): cls.root = Tk() cls.root.withdraw()
def onCancel(self): if self.threads == 0: Tk().quit() else: showinfo(self.title, 'Cannot exit: %d threads running' % self.threads)