-1

I wrote a script that keeps customer's device information shown below. Is it possible to convert this code to a GUI with Python Tkinter. How can I do it?

    print("FAILURE LOGGING PROGRAM")

filename = input ("Please enter the file name: ")+(".txt");
with open (filename, "w") as f:
    f.write ("Date: " + input ("Date: "));
    f.write ("\n\Record No: " + input ("Record No: "));
    f.write ("\n\nCustomer Name: " + input ("Customer Name: "));
    f.write ("\n\nCustomer Phone Number: " + input ("Customer Phone Number: "));
    f.write ("\n\nCustomer Adress: " + input ("Customer Adress: "));
    f.write ("\n\nDevice Type: " + input ("Device Type: "));
    f.write ("\n\nTrademark : " + input ("Trademark: "));
    f.write ("\n\nImei Number: " + input ("Imei Number: "));
    f.write ("\n\nFailure Explanation: " + input ("Failure Explanation: "));
    f.write ("\n\nRepair Price: " + input ("Repair Price: "));
    f.write ("\n\nExpected Repair Time: " + input ("Expected Repair Time: "));
    f.write ("\n\nAnnotation: " + input ("Annotation: "));
miador
  • 1
  • 4

2 Answers2

1

Yes, it's possible. The main things you want to use are labels, entries, and buttons. Labels display text, entries get text inputs, and buttons are buttons that call functions.

Here is A Basic Example:

#You Shouldn't Always Import Tkinter Like This, But In This Case, You Can
from tkinter import *
class GUI:
    def __init__(master):
        """
        Specify The Master or Root Frame First, Then Any Other Parameter
        Labels: Display Text
        Entries: Get One-Line Text Inputs
        Buttons: A Button That Runs A Command
        Grid Places The Widget Wherever you Want (There Are Also Other Layouts Like Pack and Place)
        """
        Label(master,text="Label:").grid(row=0,column=0)
        self.entry = Entry(master)
        """
        Places Entry On Same Row But Not Column Of Label
        Notice How Grid Is Not Called On Constructor But On Variable Later (For More Info: https://stackoverflow.com/a/1101765/8935887)
        """
        self.ent.grid(row=0,column=1)
        Button(master,text="Click!",command=self.func).grid(row=1,column=1)
    def func(self):
        text = self.ent.get()
        print('Our Text Is:',text)
#Basically Checks If Program is not being Imported
if __name__ == '__main__':
    root = Tk()
    GUI(root)
    #Starts Tkinter Event Loop
    root.mainloop()

Another Note: You should typically make GUIs in a class, as it makes it easier later.

Brian Ton
  • 377
  • 2
  • 12
0

Yes, it is possible to convert it a million ways. Read the tutorial.

Nae
  • 14,209
  • 7
  • 52
  • 79