hello i'm new tkinter , coding. creating project called google bike. found instructable on , wanted nicer adding start menu. uses python , using tkinter create start page of sort it. trying create button press in order launch program. code used make tkinter make nice , sort of start menu.
import tkinter tk tkinter import * import ttk def openserver(): execfile("c:/users/broadway jewelry/downloads/server/server2/server.py") class camacho(tk.tk): def __init__(app): tk.tk.__init__(app) container = tk.frame(app, width=800, height=500) container.pack(side="top", fill="both", expand = true) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) app.frames = {} f in (startpage, instructionspage, optionspage, demopage): frame = f(container, app) app.frames[f] = frame frame.grid(row=0, column=0, sticky="nsew") app.show_frame(startpage) def show_frame(app, cont): frame = app.frames[cont] frame.tkraise() class startpage(frame): def __init__(app, parent, controller): frame.__init__(app, parent, background='black', width=800, height=500) earth = tk.photoimage(file="c:/users/broadway jewelry/desktop/bluestamp/earth.gif") bglabel = tk.label(app,image=earth) bglabel.image = earth bglabel.place(x=300,y=0,width=400,height=400) startprogram = button(app, text="start google bike", bd=10, command=openserver) startprogram.place(x=100,y=75,width=200,height=44) instructions = button (app, text="instructions", bd=10, command=lambda: controller.show_frame(instructionspage)) instructions.place(x=100,y=150,width=200,height=44) options = button (app, text="options/setup", bd=10, command=lambda: controller.show_frame(optionspage)) options.place(x=100,y=225,width=200,height=44) quit = button (app, text="exit program", command=quit, bd=10) quit.place(x=100,y=300,width=200,height=44) class instructionspage(frame): def __init__(app, parent, controller): frame.__init__(app, parent, background='black', width=800, height=500) label = tk.label(app, text="instructions\n \npedal=go forward\npress button=reverse\nbutton side steer", font=(200), background='black', fg='white') label.place(x=300,y=0,width=400,height=400) startprogram = button(app, text="start google bike", bd=10, command=openserver) startprogram.place(x=100,y=225,width=200,height=44) goback = button (app, text="go back", bd=10, command=lambda: controller.show_frame(startpage)) goback.place(x=100,y=300,width=200,height=44) class optionspage (frame): def __init__(app, parent, controller): frame.__init__(app, parent, background='black', width=800, height=500) goback = button (app, text="go back", width=50, bd=10, command=lambda: controller.show_frame(startpage)) goback.place(x=100,y=300,width=200,height=44) startprogram = button(app, text="start google bike", bd=10, command=openserver) startprogram.place(x=100,y=225,width=200,height=44) showdemo = button (app, text="show demo screen", bd=10, command=lambda: controller.show_frame(demopage)) showdemo.place(x=100,y=150,width=200,height=44) class demopage (frame): def __init__(app, parent, controller): frame.__init__(app, parent, background='black', width=800, height=500) earth = tk.photoimage(file="c:/users/broadway jewelry/desktop/bluestamp/google-bike.gif") bglabel = tk.label(app,image=earth) bglabel.image = earth bglabel.place(x=300,y=0,width=400,height=400) goback = button (app, text="go back", width=50, bd=10, command=lambda: controller.show_frame(optionspage)) goback.place(x=100,y=300,width=200,height=44) app = camacho() app.mainloop() i thinking of finding way close tkinter window , have python running google bike. if can thank much
just add single line openserver (which seems function runs real program):
def openserver(): execfile("c:/users/broadway jewelry/downloads/server/server2/server.py") app.destroy() i recommend that, within given class, refer instance of class standard self rather app. is, it's giving impression camacho object instantiate @ end of program being passed around , referred app name. however, not case: in camacho, app refer camacho object, if did test = camacho(). within camacho, test object refer app. in other classes, it's more misleading, camacho object named app not app in there @ all, rather controller.
confused? find messy - that's why it's better use self, , avoid using same apparent variable name in multiple scopes.
Comments
Post a Comment