Python 3中的故障记录程序



我编写了一个脚本,该脚本可在下面显示客户的设备信息。是否可以使用Python Tkinter将此代码转换为GUI。我该怎么办?

    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 ("nRecord No: " + input ("Record No: "));
    f.write ("nnCustomer Name: " + input ("Customer Name: "));
    f.write ("nnCustomer Phone Number: " + input ("Customer Phone Number: "));
    f.write ("nnCustomer Adress: " + input ("Customer Adress: "));
    f.write ("nnDevice Type: " + input ("Device Type: "));
    f.write ("nnTrademark : " + input ("Trademark: "));
    f.write ("nnImei Number: " + input ("Imei Number: "));
    f.write ("nnFailure Explanation: " + input ("Failure Explanation: "));
    f.write ("nnRepair Price: " + input ("Repair Price: "));
    f.write ("nnExpected Repair Time: " + input ("Expected Repair Time: "));
    f.write ("nnAnnotation: " + input ("Annotation: "));

是的,这是可能的。您要使用的主要内容是标签,条目和按钮。标签显示文本,条目获取文本输入,按钮是调用功能的按钮。

这是一个基本示例:

#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()

另一个注意事项:您通常应该在课堂上制作GUI,因为它以后会更容易。

是的,可以将其转换一百万个方式。阅读教程。

最新更新