Deploying Python (Tkinter) Desktop UI in Azure – Ultimate Guide for the Simplest & Effective Method

El Mehdi Ouafiq 0 Reputation points
2024-04-12T17:48:48.1233333+00:00

Dears,

I want to deploy a User Interface (UI) in Azure to give access to the end-user. This “desktopUI was built (in my local machine directly without any container or VM) using customtkinter library in Python (and PyCharm as IDE), which is based on Tkinter library (as you can see in the picture below).

import tkinter
import tkinter.messagebox
import customtkinter

Just for your information, the UI imports a pickle file that executes an ML algorithm from which it generates predictions based on user inputs. The UI is as simple as you can see in the picture below:

2 UI

I’m looking for the simplest way to deploy it in Azure which is less costly but not very limited in term of performance (of execution, reading inputs and visualizing the outputs). The purpose is as simple as:

1.       Deploying the code in Azure,

2.       Generating “.exe” or any other method that enable the “business” user to launch the UI with simple click, without having to go to the code and execute it from there.

I listed two methods below, which I’m not sure if they are the appropriate ones. So, please feel free to propose the simplest one (based on your experience & specialty), and if you have any simple steps to suggest, kindly share them.

1.       Building a Microsoft virtual machine and deploying the UI there. The concern here is: Since we are using “Azure ML” to train the ML model, would it be easy to push the pickle file (that the UI uses) to the VM? Are there any constraints or limitations?  Would it be user friendly for “business” users to go to the UI and execute it in this VM?

2.       Azure App Service and/or Azure Logic Apps to deploy the UI as a web app. The concern here is: The UI is built as a desktop app using Tkinter. Thus, would it be necessary to convert our code using other libraries/APIs like Django or Flask (which is the last thing we want to do)?

3.       Or any other method that you propose/recommend. The purpose is to select the simplest way which not limited in term of performance!

Thanks!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,144 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,851 questions
Azure Virtual Desktop
Azure Virtual Desktop
A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.
1,364 questions
Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,248 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,900 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sina Salam 3,721 Reputation points
    2024-04-12T22:15:42.6566667+00:00

    Hello El Mehdi Ouafiq,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    Sequel to your questions, I understand that you seek guidance on deploying your Tkinter-based Python desktop UI in Azure while considering simplicity, performance, and cost-effectiveness. Also, you are facing challenges in selecting the appropriate deployment method, ensuring seamless access to the ML model and data, and preserving the functionality of the UI without extensive modifications.

    Scenarios

    • You need to choose between Azure Virtual Machine and Azure App Service, weighing factors such as ease of deployment, performance, and cost.
    • You want to devise a strategy for efficiently transferring the pickle file containing the ML algorithm to the Azure environment, ensuring seamless integration with the UI.
    • You also aim to maintain the simplicity and functionality of the Tkinter-based desktop UI while exploring deployment options in Azure, without resorting to converting it into a web application.

    Solution

    Deploying a Tkinter-based Python desktop UI in Azure while maintaining simplicity and performance can indeed be achieved without resorting to major code restructuring. Let's explore some of the options available:

    Azure Virtual Machine (VM):

    You can create a VM instance and deploy your Tkinter-based UI there. This approach offers flexibility in terms of environment configuration. Uploading the pickle file to the VM shouldn't be an issue. You can use Azure Storage to store the pickle file and then retrieve it within your VM. You can make the UI accessible to business users by configuring remote access to the VM. Tools like Remote Desktop Protocol (RDP) can enable users to interact with the UI as if it were on their local machine.

    Pros

    • No significant modifications to the UI are necessary, allowing for the preservation of its functionality.

    Cons

    • The downside is managing the VM instance, including updates, security, and scalability. It might not be the most cost-effective solution, especially if the usage is sporadic.

    Azure App Service:

    While Azure App Service is primarily for web applications, you can still deploy desktop applications with some tweaks. One approach is to use Flask or Django to create a lightweight web service that hosts your Tkinter UI. The UI itself can remain unchanged, but it communicates with the backend via HTTP requests. To simplify deployment, you can package your Tkinter app along with the Flask or Django server into a single executable using tools like PyInstaller or Py2exe.

    Cons

    • This approach might require some refactoring but allows you to leverage Azure's managed services for scalability and maintenance.
    • It's essential to consider the performance implications of running a Tkinter app within a web service, especially if there are many concurrent users.

    Other Methods:

    Another option is to explore Azure Container Instances (ACI). You can containerize your Tkinter app and deploy it as a container in ACI. This approach provides isolation and scalability without the overhead of managing VMs. You can also investigate Azure Functions, especially if your UI functionality can be broken down into smaller, serverless components.

    Cons

    • However, Tkinter might not be the best fit for this approach.

    Finally

    If you are familiar with Cloud and virtualization architecture or you're with a good solution architect, as a solution architect I will advise you to start with VM on Azure and if otherwise.

    Considering your requirements for simplicity and performance, I recommend starting with Azure App Service. While it involves some refactoring, it provides a balance between ease of deployment and scalability. Additionally, packaging your Tkinter app with Flask or Django into a single executable can simplify the deployment process for your business users.

    References

    Kindly utilize the additional documents available by the right side of this page.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments

  2. kobulloc-MSFT 23,491 Reputation points Microsoft Employee
    2024-04-15T19:25:04.9566667+00:00

    Hello, @El Mehdi Ouafiq !

    What is the best approach for deploying a desktop app that can be accessed by end users?

    My recommendation would be Azure Virtual Desktop or possibly Azure Lab Services depending on your specific needs. Generally speaking, the approach would be the same in that you create a base VM image with your desktop application which is then used on different VMs by your users.

    Azure Virtual Desktop allows you to run Windows 10, 11, or Server to offer full desktops or use RemoteApp to deliver individual apps. This allows you to deliver Software-as-a-service (SaaS) for external usage. Setup can be a bit more complicated however this is likely the best match for what you've described. The overview is worth going through but this is the tutorial for deploying a sample Windows 11 Azure Virtual Desktop:

    https://learn.microsoft.com/en-us/azure/virtual-desktop/tutorial-try-deploy-windows-11-desktop?tabs=windows-client

    Azure Lab Services allows you to create virtual machine labs with infrastructure managed by Azure. Azure Lab Services is great for classrooms, training, research, and hackathons. It's also simple to setup and maintain. If that sounds more like what you are interested in, then this quickstart will get you started:

    https://learn.microsoft.com/en-us/azure/lab-services/quick-create-resources

    Not recommended

    I wouldn't recommend Azure Virtual Machines or Azure Virtual Machine Scale Sets simply because it introduces more security concerns (you would need to give users access to VMs within your subscription) and overhead (spinning up VMs on demand for users, among other things).

    Azure App Service is a great for hosting web apps, mobile back ends, and RESTful APIs rather than desktop applications. Azure Logic Apps allows you to create and run automated workflows which can supplement applications but wouldn't be used to host an application.

    Additional architecture guidance

    When choosing a compute service, you may want to refer to the Azure Architecture Center:

    https://learn.microsoft.com/en-us/azure/architecture/guide/technology-choices/compute-decision-tree

    Diagram that shows a decision tree for Azure compute services.


    I hope this has been helpful! Your feedback is important so please take a moment to accept answers.

    If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    User's image

    0 comments No comments