在Python中获取特定的用户输入字符

问题描述

我是一个初学者,刚刚开始探索Tkinter和Python编程。我遇到了一个Tkinter程序模板,我想在上面测试一些功能。当前,该部分允许用户输入ID值,并且从数据库中将varchar设置为45。我有一个条形码读取器,当我扫描时会在其中生成输出,例如“ ID:ffffff100 ..... n SN”。 :SK1980 .... n“。有什么办法让我只接受“ ffffff100 .... n”中的值吗?这样一来,当我扫描和添加时,它只会从“ fff插入到n(不包括ID:和SN:SK19..n)?我有什么选择?enter image description here我附加了一些代码段,我相信这是相关的片段和图片供您参考。

#Entry Type: Register New Asset
elif (choices == "Register New Asset"):
    test1 = Check(temp_Entry.get(),gps_Entry.get(),current_Entry.get())
    if (test1 == "TRUE"):
        command = ("SELECT `Asset ID` FROM `Asset IDs` WHERE `Asset ID` = %s")
        mycursor.execute(command,(ID_Box.get(),))
        results = mycursor.fetchall()
        
        if len(results) == 0:
            command = ("INSERT INTO `Asset IDs` (`Asset ID`) VALUES (%s)")
            mycursor.execute(command,))
            connection.commit()
            
        command = ("SELECT `Device EUI` FROM `Temp/Hum Sensors` WHERE `Device EUI` = %s")
        mycursor.execute(command,(temp_Entry.get(),))
        results = mycursor.fetchall()
        
        if len(results) == 0:
            command = ("INSERT INTO `Temp/Hum Sensors` (`Device EUI`) VALUES (%s)")
            mycursor.execute(command,))
            connection.commit()

        command = ("SELECT `Device EUI` FROM `GPS Sensors` WHERE `Device EUI` = %s")
        mycursor.execute(command,(gps_Entry.get(),))
        results = mycursor.fetchall()
            
        if len(results) == 0:
            command = ("INSERT INTO `GPS Sensors` (`Device EUI`) VALUES (%s)")
            mycursor.execute(command,))
            connection.commit()
        
        command = ("SELECT `Device EUI` FROM `Current Sensors` WHERE `Device EUI` = %s")
        mycursor.execute(command,(current_Entry.get(),))
        results = mycursor.fetchall()
            
        if len(results) == 0:
            command = ("INSERT INTO `Current Sensors` (`Device EUI`) VALUES (%s)")
            mycursor.execute(command,))
            connection.commit()
        
        command = ("INSERT INTO `Inventory` (`Asset ID`,`Equipment Type`,`Temp/Hum EUI`,`GPS EUI`,`Current EUI`,`Status`,`Remarks`) VALUES (%s,%s,%s)")
        val = (ID_Box.get(),asset_Box.get(),temp_Entry.get(),current_Entry.get(),status_Entry.get(),remarks_Entry.get())
        mycursor.execute(command,val)
        connection.commit()

        tkinter.messageBox.showinfo("Register New Asset","Successfully registered!")
        
        clear_fields([asset_Box,ID_Box,temp_Entry,gps_Entry,current_Entry,name_Entry,company_Entry,email_Entry,contact_Entry,issue_Entry,return_Entry,status_Entry,remarks_Entry,issuehours,issueminutes,issuedays,returnhours,returnminutes,returndays])
        entry_Box.configure(state="normal")
        entry_Box.delete(0,"end")
        entry_Box.insert(0,"Select the following")
        entry_Box.configure(state="readonly")
        entry_Box.focus()

        addbutton.configure(state="disable")
    else:
        valueErrorMessage = "Invalid input for " + test1 
        tkinter.messageBox.showerror("Error",valueErrorMessage)

command = "SELECT `Asset ID` from `Inventory`"
mycursor.execute(command)
results = mycursor.fetchall()

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)