Post History

Thursday, July 18, 2013

Python GUI (Graphics User Interface) for Prime Finder Program

    I've wondered, how the heck do I get something on screen!? Pretty much every program I've worked with used text in the Python Shell or command line. And so, I found this -- Python GUI

    There are many Python GUIs that will help you get your program up and running in a window, and I chose Tkinter.

Why?

Well, it comes with Python and it seemed like the simplest one to start out learning.

So here is the code for making my Prime Finder function work in a window:


And the result should look something like this:


Here is the copy pasta:

import sys
from tkinter import *

def Prime_finder():
    mtext = ment.get()
    if mtext < 2:
        return False
    else:
        count = 0
        for i in range(1, mtext + 1):
            if mtext % i == 0:
                count += 1
        if count == 2:
            l = Label(mGui, text="True").pack()
        else:
            l = Label(mGui, text="False").pack()
    return

mGui = Tk()
ment = IntVar()

mGui.geometry("450x500+400+200")
mGui.title("$$$$Prime Number Finder$$$$")

mlabel = Label(mGui, text="Enter Your Prime Number").pack()

mbutton = Button(mGui, text = "Check", command = Prime_finder).pack()

mEntry = Entry(mGui, textvariable=ment).pack()


I learned this from a youtube user: TheReimber

Here is the video that made my little program possible. Enjoy!



No comments:

Post a Comment