1

I have a standalone application on my desktop written in Python. I am using modules like Tkinter, cv2, numpy in my application. My Tkinter renders my GUI (which has a button and an image). Now my issue is that I want to make it a web application. For this purpose, I am using Django framework which asks to segregate Model ,View and Template(MTV) . How do I render the same GUI with the same buttons and images using HTML. (My GUI having buttons and image should be in the Template while my business logic should be in View.) This is the piece of code which I want to convert to MTV Form. I want the Upload button to be in the Template(HTML). Onclick of the Upload button the program should go to the View(Logic).How do I segregate the logic and the HTML? (Is it even necessary? Can i convert the entire thing to Django framework without segregating) Please Help.

def upload():

    global original_img,img,img2,img3,image_path,old_label_image,photo,label,image_path,image,ax,fig
    print "upload"
    image_path=tkFileDialog.askopenfilename()
    image = Image.open(image_path)
    original_img= image.copy()
    image.thumbnail((1000,625))
    photo = ImageTk.PhotoImage(image)
    label = Label(image=photo)
    label.image = photo
    if old_label_image is not None:
        old_label_image.destroy()
        old_label_image = label
    #label.update()
    label.pack()

root = Tk.Tk()  #  creating an instance of Tk class
print "main"

old_label_image = None
frame = Frame(root)   #creates a new window (given by the pathName argument) and makes it into a frame widget.The frame command returns the path name of the new window.
frame.pack() #The Pack geometry manager packs widgets in rows or columns
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

UploadButton = Button(frame, text="Upload", command= upload)
UploadButton.pack( side = LEFT)

root.mainloop()

3 Answers 3

2

You can't. Here's the reasoning for those who'd like to understand:

1st-- Python code is executed by it's interpreter, a program written in C. (The Python Software Foundation's Interpreter is properly called "Cpython" to distinguish it from third parter Interpreters that can also run Python code). Python code is interpreted by Cpython, and it displays it's content into a python console, like "Idle" or a "Terminal Emulator" or even directly on the Computer Window's screen as graphics, using the "X11" [X Windows for Linux Unix], "Quartz Compositor MacX" [Macintosh], [or "DWM" [Destop Windows Manager for Windows]. (Cpython has 3 basic versions, one implementation each for Mac, Windows and Unix/Linux)

2nd-- You can also think of a web browser as a program interpreter. But it can't interpret Python code. All they knows how to interpret is HTML, CSS and Javascript. But instead of being fed out to third party console or the computers Windowing System, the Web Browser acts like a Virtual Machine in that it interprets AND displays the results within it's own display environment, the Web Browser. Unfortunately, none of those browsers have been programmed to interpret Python Code.

3rd-- Python is a VERY high level language, meaning that it was designed by lower level languages. Before there was Python there had to be C. Before there was C there had to be Assembly. Before there was Assembly there had to be Machine Language. Computer Code evolves in complexity in a way that can be compared to biology, sort of. Javascript is also VERY highly evolved, but it's evolution was entirely dependent on Web Browsers. Python's evolution depended on Terminal Emulators and a computer's Windowing System [X11, MacX, or DWM]

Sign up to request clarification or add additional context in comments.

Comments

1

You can't "convert" code like this. Writing applications for the web is completely different to writing them for a desktop framework. You'll need to think about how to present your form in HTML, how to accept the uploaded file, how to present the response to the user, and so on. Django has functionality for all of these, but it's a totally different way of doing things: for one thing, the initial presentation of the form and the returning of the response will be done in separate requests, with no persistence between them.

Comments

0

I think it would be possible if you were not using a GUI library like tikinter. there is a lot of possibilities when it comes to the python language in general. Especially it's famous framework Django

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.