Writing Software is Hard

No, it’s not. Try writing some desktop apps.
What get’s hard is to plan, automate, build and add security, cloud login configurations, data retrieval, etc.
To start, you will need a PC with internet and Python.
Please see my initial blog tutorial for installing Python or for a refresher on that first.

Set your graphics to a higher number display pixels. The demo code in this sample will use at least 680 pixels in horizontal display.

Next, load python and install TclTkInter toolkit. This can work on windows and linux. I am not sure if it works on Mac. If it does, let me know and let us all know! For now, lets assume you are on a linux or windows box. Most of my introductions are on a windows desktop.

TclTkInter window app

We’ll create a simple window app with icon and file menu. I think you will be amazed how simple it is. Modern Python uses spaces to indent so if you download this and it’s complaining cause you have tabs just change them all to spaces in the indentation.

Create a directory called C:\Work\Python\sampleUI.py

To start, open a text editor and type:

import tkinter as tk

class Example(tk.Frame):

    def __init__(self, root):
        super().__init__(root)
        self.initUI()
        menubar = tk.Menu(self.master)
        self.master.config(menu=menubar)

        fileMenu = tk.Menu(menubar)
        fileMenu.add_command(label="New")
        fileMenu.add_command(label="Open")
        fileMenu.add_command(label="Save")
        fileMenu.add_separator()
        fileMenu.add_command(label="Exit", command=self.quit)
        menubar.add_cascade(label="File", menu=fileMenu)

    def initUI(self):
        self.master.title("JMunroDesign TclTkInterUI")
		
def main():
    root = tk.Tk()
    ex = Example(root)
    root.geometry('680x300')
    root.iconbitmap('logo.ico')
    root.mainloop()

if __name__ == '__main__':
    main()
		

Save this. Also, open paint and create a 16×16 or 32×32 icon bitmap with the software’s logo. Save that into the same directory called logo.bmp. Save it and rename it logo.ico.

Run the program by typing: python sampleUI.py. You should see:

You’ll notice some new things that were not in the introductory python. Like, a class and that thing called a tk.Frame. The TkInter toolkit is written for TclTk Python that can create User Interfaces for desktop applications so that you can have things like menus, icons, main screen area called a “Frame” and such. I also know a bit of Microsoft’s MSVC “SDK” that can create the same thing. But, that is more code, and syntax is harder to understand since it’s in C.

In my next segment on this post, I will introduce InnoSetup and how to build a setup exe to install it to windows.

Let me know what you think of this. Build things on it and let me know what you make. Add to the file open/save boxes (there are plenty of tutorials online) and add functions to save custom reports. Add security and databases, etc. Now, go have fun!

Last Updated 4/11/2024

By Jason

I'm Jason. Senior Consultant at jmunrodesign.

Leave a comment

Your email address will not be published. Required fields are marked *