Tkinter文本框向后

时间:2019-02-19 15:18:27

标签: python-3.x tkinter

我正在尝试使用tkinter制作我的第一个GUI。我已经成功制作了文本框和文件浏览按钮,并且具有基本功能,但是我的文本倒置输出到文本框中。

我尝试将行Text_Box.insert('1.0', "\nTransfer to wifi selection page")更改为Text_Box.insert('end', "\nTransfer to wifi selection page"),但这没有用。

# Zack Garris
# 1-28-2019
# SQL to readable text
#add a time stamp!!
import _sqlite3
import re
import tkinter as tk
from tkinter.filedialog import askopenfilename
from _sqlite3 import Error
import _sqlite3

def create_connection(db_file):
    try:
        conn = _sqlite3.connect(db_file)
        return conn
    except Error as e:
        print(e)

    return None

###########################################
try:
    UserFile = open("UserFriend.txt", "w")
                                            #Check for File if one does not exist make it
except:
    UserFile = open("UserFriend.txt", "w+")
###########################################

global Error
Error = False


#type1 = "Crash"
#type2 = "Connection Issue"

#cause1 = "Possible too far away"
#cause2 = "Poor connection with router with eiter phone or appliance"

def Friendly_Output(line,number,times):
    # Begin Searching
    #print(line, number)
    ############################################################################
    if "viewDidLoad() - Got a valid" in line and Error == False:
        UserFile.write("\nFound mac address here")
        Text_Box.insert("1.0", "\nFound mac address here")
    else:
        pass
        ########################################################
    if Error == False and "wifiScanTimerEvent(timer:)" in line:
        UserFile.write("\nPinged nearby wifi with NIC " + str(times) + " time(s)")
        Text_Box.insert("1.0", "\nPinged nearby wifi with NIC " + str(times) + " time(s)")
        ########################################################
    if Error == False and "refrigeratorTapped()" in line:
        UserFile.write("\nTransfer to Pin Entry")
        Text_Box.insert('1.0', "\nTransfer to Pin Entry")
    else:
        pass
        ########################################################
    if Error == False and "applianceTapped() - segue_to_wifi_select_sid" in line:
        UserFile.write("\nTransfer to wifi selection page")
        Text_Box.insert('1.0', "\nTransfer to wifi selection page")
    else:
        pass
        ########################################################
    if Error == False and "prepare(for:sender:) - segue_to_prod_wifi_setup_sid" in line:
        UserFile.write("\nTransfer to Wifi crediental entry screen")
        Text_Box.insert('1.0', "\nTransfer to Wifi crediental entry screen")
    else:
        pass
    if Error == False and "addWifiNameToParamOut(wifi:)" in line:
        UserFile.write("\nAdded wifi to data send list")
        Text_Box.insert('1.0', "\nAdded wifi to data send list")
    else:
        pass
        ########################################################
    if Error == False and "setDevicePrivilegeCloud(macAddress:userApiKey:devicePin:privilegeCompletionHandler:) - Called with" in line:
        UserFile.write("\nSent MacAddress, apiKey, and devicePin to Cloud")
        Text_Box.insert('1.0', "\nSent MacAddress, apiKey, and devicePin to Cloud")
    else:
        pass
        ########################################################
    if Error == False and r"setDevicePrivilegeCloud(macAddress:userApiKey:devicePin:privilegeCompletionHandler:) - \nDevice" in line:
        UserFile.write("\nSuccessful sending of  MacAddress, apiKey, and devicePin to Cloud")
        Text_Box.insert('1.0', "\nSuccessful sending of  MacAddress, apiKey, and devicePin to Cloud")
    else:
        pass
        ########################################################
    if Error == False and "onRecordButton" in line:
        UserFile.write("\nEntry applied to appliance list (Continue Button)")
        Text_Box.insert('1.0', "\nEntry applied to appliance list (Continue Button)")
    else:
        pass
        ########################################################
    '''
    if Error == False and "updateApplianceRecord() - upda" in line:
        UserFile.write("\nUser notified of success")
    else:
        pass
    '''
        ########################################################
    if Error == False and "updateApplianceRecord() - upda" in line:
        UserFile.write("\nUser notified of success")
        UserFile.write("\nEnd of Setup number: " + str(number) + "\n\n")
        Text_Box.insert('1.0', "\nUser notified of success\nEnd of Setup number: " + str(number) + "\n\n")
    else:
        pass

    #while "waitTimerSerialNumEvent" in line and limit < 1:
    #    pass
#setupChangeNotification() - Calling
                #ERROR GRAB
################################################################################

    if   "0110" in line:
        UserFile.write("\nERROR: No Bluetooth device was found")
        Text_Box.insert('1.4',"\nERROR: No Bluetooth device was found")
    elif "0120" in line:
        UserFile.write("\nERROR: No Wifi or Poor Connection")
        Text_Box.insert('1.0', "\nERROR: No Wifi or Poor Connection")
    elif "0130" in line:
        UserFile.write("\nERROR: User searched for appliance but none was found")
        Text_Box.insert('1.0', "\nERROR: User searched for appliance but none was found")
    elif "300" in line:
        UserFile.write("\nERROR: Wifi List is empty. Restarting configure process.")
        Text_Box.insert('1.0', "\nERROR: Wifi List is empty. Restarting configure process.")
    elif "310" in line:
        UserFile.write("\nERROR: Lost BluetoothConnection in Wifi Picker Screen. Restarting configure process.")
        Text_Box.insert('1.0', "\nERROR: Lost BluetoothConnection in Wifi Picker Screen. Restarting configure process.")
    elif "1010" in line:
        UserFile.write("\nERROR: User opted to skip wifi Setup")
        Text_Box.insert('1.0', "\nERROR: User opted to skip wifi Setup")
    elif "1011" in line:
        UserFile.write("\nERROR: There was an empty text field when trying to configure wifi")
        Text_Box.insert('1.0', "\nERROR: There was an empty text field when trying to configure wifi")
    elif "1012" in line:
        UserFile.write("\nERROR: Bluetooth Disconnected, Reason Unknown")
        Text_Box.insert('1.0', "\nERROR: Bluetooth Disconnected, Reason Unknown")
    elif "1013" in line:
        UserFile.write("\nERROR: The provision watchdog timer has timed out without response from NIC")
        Text_Box.insert('1.0', "\nERROR: The provision watchdog timer has timed out without response from NIC")
    elif "1029"  in line:
        UserFile.write("\nERROR: The Cloud Service reports error. Error in log")
        Text_Box.insert('1.0', "\nERROR: The Cloud Service reports error. Error in log")
    elif "1030" in line:
        UserFile.write("\nERROR: The provisioning has failed.  The device and apikey key were not returned")
        Text_Box.insert('1.0', "\nERROR: The provisioning has failed.  The device and apikey key were not returned")

################################################################################
def main(filename):

    list = create_connection(filename)  # create_connection(database)
    global Error
    cur = list.cursor()
    cur.execute("SELECT error_text from error_log ")
    rows = cur.fetchall()

    count = 0
    pings = 1
    hits = 0
    info = []
    for row in rows:
        info.append(row)
#Regex Grab
#########################################################################
    m = re.search(r"(?s)id: (?P<username>.+?) - (?P<password>.+?)'.*Appliance: (?P<modelnumber>\S+).*macAddress: (?P<macaddress>.+?)'.*appl name: (?P<applname>\S+)", str(info))
    if (info):
        try:
            UserFile.write('Username: {}, Password: {}, Modelnumber: {}, Macaddress: {}, applname: {}\n\n'.format(m.group('username'),m.group('password'),m.group('modelnumber'),m.group('macaddress'),m.group('applname')))
            for row in rows:

                Friendly_Output(str(row), count, pings)
                info.append(row)
                if "onRecordButton - Calling" in str(row):
                    count = count + 1
                    pings = 1
                if "wifiScanTimerEvent(timer:)" in str(row):
                    pings = pings + 1
        except:
            print("Type None Occured")





# GUI
################################################################################
window = tk.Tk()

window.title("SQL to Text")
window.geometry("450x1000+225+500")

def Load_File():
    fname = askopenfilename(filetypes = (("SQL Database", "*.db"), ("All Files","*.*")))
    main(fname)
    #Text_Output()

#Label
label = tk.Label(text="Click Here to Browse")
label.grid(column = 0, row = 0)



#Browse_Button
Browse_Button = tk.Button(text = "Click Me!", command = Load_File)
Browse_Button.grid(column = 0, row = 1)

#Text field
Text_Box = tk.Text(height = 50, width = 50, background = "black", foreground = "white")
Text_Box.grid(column = 0, row = 2)



window.mainloop()



############################################################################################

0 个答案:

没有答案