My current program is text based, is there a way to convert it to a GUI based one?

import sqlite3
from tkinter import*
import sys
import random
from random import shuffle
import time

#-------------------------------------------------------------------------------------------------------
def database1():
    conn = sqlite3.connect("Database1.db") #connection to database
         #directory will need to be changed in order to work
    cur = conn.cursor()
    cur.execute("SELECT ID, Difficulty, Questions, Answers FROM Table1"); #SQL CODE for access database

    while True:
        row = cur.fetchone()
        if row is None:
            break
        pre_diff_array.append(row)
    cur.close()
    conn.close()

def highScoreA(x): #scores for level A
    import csv
    import shlex
    global fecha
    fecha = str(time.strftime("%d/%m/%Y"))
    fd = open('ScoresA.txt','a')
    value = str(uInfo)[1:-1] #removes the brackets from list
    Fin=value.translate(str.maketrans({"'":None}))#removes quote marks 
    result=str(Fin).replace(" ", "")#removes spacing 
    fd.write(result+"\n")
    fd.close()

def highScoreB(x): #scores for level B
    import csv
    import shlex
    global fecha
    fecha = str(time.strftime("%d/%m/%Y"))
    fd = open('ScoresB.txt','a')
    value = str(uInfo)[1:-1] #removes the brackets from list
    Fin=value.translate(str.maketrans({"'":None}))#removes quote marks 
    result=str(Fin).replace(" ", "")#removes spacing 
    fd.write(result+"\n")
    fd.close()

def highScoreC(x): #scores for level C
    import csv
    import shlex
    global fecha
    fecha = str(time.strftime("%d/%m/%Y"))
    fd = open('ScoresC.txt','a')
    value = str(uInfo)[1:-1] #removes the brackets from list
    Fin=value.translate(str.maketrans({"'":None}))#removes quote marks 
    result=str(Fin).replace(" ", "")#removes spacing 
    fd.write(result+"\n")
    fd.close()    

def inco():
    repeats = []
    Rescore = []

    print("Your score was: "+ str(score))

    print("Oh no looks like struggled at some questions")

    decide = input("""Looks like you need somemore pracitce, would you like to try again
                     please enter either y or n: """).upper()

    incans = [row[3] for row in array] #all incorrect answers
    incque = [row[2] for row in array] #all incorrect questions

    count = 0

    q = len(incorrect) #shows how many elements in array
    for i in range(q): #makes a dynamic loop based on number of elements in  ^^
        incuser = random.choice(incorrect)
        selectedQ = incuser[2]
        selectedA = incuser[3]

        if decide == "Y":

            print("starting")

            order1 = [selectedA,random.choice(allans),random.choice(allans)]

            print("1."+ order1[0]+ " "+"\n"+"2."+order1[1]+"\n"+"3."+order1[2])
            print("Please selct either 1,2,3")
            try:
                ask1 = int(input("What is the meaning of" + " " + selectedQ + ":"))
            except:
                print("Incorrect input")
                showQuestion(selectedA,incans,incque)

            opt1 = [1,2,3]

            if (ask1 not in opt1):
                print("Pick between 1-3")

            else:
                ask1 = int(ask1)
                if(order1[int(ask1)-1]==selectedA):
                    print("\n"+ "Correct! 10 Points")
                    print(" " )

                    incorrect.remove(incuser) #remove question
                    Rescore.append(10)

                else:
                    print(" ")
                    print("Sorry, incorrect")
                    wrongWords(str(incuser)) #for the frequent incorrect words

                count = count + 1

            if count == q:
                print("Done")
                global tot
                tot = sum(Rescore) #tot means total
                print("Your new score is" + " " +str(tot))
                appendCheck()

def wrongWords(z):
    ff = open('wrongWords.txt','a')
    ff.write(z+'\n' )
    ff.close()

def appendCheck():
    global uInfo
    uInfo = str([sco,fecha])
    if currentDif =='a' or currentDif =='A':
        highScoreA(uInfo)
    elif currentDif =='b' or currentDif =='B':
        highScoreB(uInfo)
    else:
        highScoreC(uInfo)               

def startUp():
    print("""Welcome to the verb tester
         Here you can start testing your self
    """)    
    while True:     
        try:
            choice = input("would you like to start, please enter either Y or N").upper()   
        except:
            print("Error: can\'t find file or read data")

        if choice == "Y":
                main(0,0,"")
        elif choice == "N":
            print("Thank you for your time")
            print("Closing application")
            sys.exit()

def lim():
    global limit
    global score
    global currentDif

    if limit == 0:
        if score <= 30:
            inco()
            volver = input("Would you like to return back to the main menu?").upper()
            if volver == "Y":
                startUp()
            else:
                print("Thank you for your time")
                sys.exit()
        else:
            global sco
            sco = str(score)

            print("Your score was: "+ sco)#]]]]]]]]]]]]]]]]]][][][][]
            global fecha
            fecha = str(time.strftime("%d/%m/%Y"))
            appendCheck()

            again = input("""
                       Would you like to try the next level?
                       Type y or Y for Yes
                            n or N for No
                    """)
            res = ['y','Y','n','N']
            cor = False
            while cor == False:
                if again not in res:
                    again = input("Enter a valid response!")
                else:
                    cor = True
            if again == "y" or again == "Y":
                letters = ["a","b","c"]
                nextLevel = ""
                pos = 0
                score = 0
                tot = 0
                sco = 0

                for x in range(len(letters)):
                    if letters[x] == currentDif:
                        pos = x

                if currentDif != "c":

                    nextLevel = letters[pos+1]
                    pos = pos + 1

                    print(nextLevel)
                    currentDif = nextLevel
                    limit = 5
                    main(1,1,nextLevel)
                else:
                    print("This is the hardest level!")
                    sys.exit()
            else:
                sys.exit()

def genQuestion():
   global array
   global allans
   global allque
   for i in range(0,6):

    user = random.choice(array)#--------

    shuffle(array)
    question = user[2]
    answer = user[3]
    allans = [row[3] for row in array] #all answers
    allque = [row[2] for row in array] # all questions

    return [answer,allans,question,user]

def removeDuplications(choices,allans):
    dup = True
    while dup == True:
        dup = False
        for ans in range(len(choices)-1):
            if choices[ans] == choices[ans+1]:
                choices[ans+1] = random.choice(allans)
                dup = True

    return choices

def showQuestion(answer,allans,question,user,correct):
    global score
    global limit

    order = [answer,random.choice(allans),random.choice(allans)]
    order = removeDuplications(order,allans)
    if correct == 0:
        print("1."+ order[0]+ " "+"\n"+"2."+order[1]+"\n"+"3."+order[2])
        print("Please selct either 1,2,3")

    try:
        ask = int(input("What is the meaning of" + " " + question + ":"))
    except:
        print("Incorrect input")
        showQuestion(answer,allans,question,user,1)

    opt = [1,2,3]

    if (ask not in opt):
        print("Pick between 1-3")
        showQuestion(answer,allans,question,user,1)
    else:
        ask = int(ask)
        if(order[int(ask)-1]==user[3]):
            print("\n"+ "Correct, 10 points")
            print(" " )
            array.remove(user) #remove question
            score = score + 10
            lim()
            limit = limit -1
            x = genQuestion()
            showQuestion(x[0],x[1],x[2],x[3],0)
            points.append(10)

        else:
            incorrect.append(user) #- appends incorrect answers to incorrect array
            print(" ")
            print("Sorry incorrect")
            wrongWords(str(user))
            print(" ")
            lim()
            limit = limit - 1 #for the number of iterations
            x = genQuestion()
            showQuestion(x[0],x[1],x[2],x[3],0)

def subMain(letter):
    for element in pre_diff_array:
        if element[1]== letter:
            array.append(element)

    x = genQuestion()
    #[answer,allans,question,user,correct]
    showQuestion(x[0],x[1],x[2],x[3],0) 

def main(dif,nL,d):
    #NL is 0 1 where 0 is not the next level and 1 is the next level
    #Where d is the next level
    global currentDif
    database1()
    if nL == 0:
        if dif == 0:
            print("Please select either A,B, or C")
            print(" ")
            choice = str(input("what level of difficulty would you like:")).upper()
            letters = ["a","A","b","B","c","C"]
            if choice not in letters:
                print("Enter valid input")
                main(0,0,"")
            else:
                if choice == "a" or choice == "A":
                    dif = dif + 1
                    currentDif = "a"
                    subMain("a")
                if choice == "b" or choice =="B":
                    currentDif = "b"
                    subMain("b")
                if choice == "c" or choice =="C":
                    currentDif = "c"
                    subMain("c")
    else:
        subMain(d)
#-------------------------------------------------------------------------------------------------------
#Main

currentDif = ""
array =[]
points =[]
incorrect =[]
a = []
b = []
c = []
pre_diff_array=[]             
limit = 5             
score = 0

startUp()

#main(0,0,"")

Yes. There is a way to convert it to a GUI based program.

Before you do that, I would recommend:

  • Make a self containained version, so others can run it. That helps you to get help.
  • Make the program shorter. At first glance the program can be reduced at least to half size without hurting readability and functionality.
  • Write function documentation. The aim of the documentation is to tell the reader what the function is intended to do. Not how it is intended to accomplish it. If you cannot formulate the purpose of the function in one sentence, then something is wrong.
  • Also meaningless naming is burden to understandability. array, database1, a, b, c.
  • Try to get rid of global immutable changing variables. Document and name the globals as if they were functions.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.