[问题] 如何在if语句中使用编码文本? 即使变量(serialNumberValue + encodedValue)具有相同的类型,也不会执行以下快乐流程代码。
[当前输出] 快乐的流程代码将无法执行。
[期望的输出] 快乐的流程代码应该被执行。
[CODE]
# Initiliaze secure window
import wx
secureApp = wx.App(False)
topSecure = wx.Frame(None, title=" test - Enter serial number", style=wx.MINIMIZE_BOX | wx.CAPTION | wx.CLOSE_BOX)
topSecure.Center()
topSecure.SetBackgroundColour('LIGHTGREY')
topSecure.SetSize(360,150)
def validateSerialNumber(event):
print "test"
serialNumberValue = serialNumber.GetValue()
print "serialNumberValue is: ", serialNumberValue
import platform
print platform.node()
encodedValue = platform.node().encode("base64")
print "encodedValue type is: " , type (encodedValue), encodedValue
print "serialNumberValue type is: " , type (str(serialNumberValue)), serialNumberValue
if (str(serialNumberValue)) == encodedValue:
print "ok"
topSecure.Destroy()
else:
print "not ok"
import wx
dial = wx.MessageDialog(None, 'Serial number invalid.', 'test - serial number', wx.OK)
dial.ShowModal()
sizer = wx.GridBagSizer()
# Add serial number label
serialLabel = wx.StaticText( topSecure, wx.ID_ANY, "Enter serial number:", wx.DefaultPosition, wx.DefaultSize, 0, )
sizer.Add(serialLabel,(1,2),(1,2), flag=wx.TOP|wx.BOTTOM, border=1)
# Add serial number textbox
serialNumber = wx.TextCtrl(topSecure, -1, "", size=(175, -1))
sizer.Add(serialNumber,(2,2),(2,14),wx.EXPAND)
# Add ok button
okButton = wx.Button(topSecure, -1, "OK", (160,100), size=(45, -1))
sizer.Add(okButton,(5,12),(1,1),wx.EXPAND)
topSecure.Bind(wx.EVT_BUTTON, validateSerialNumber, okButton)
topSecure.SetSizer(sizer)
topSecure.SetFocus()
topSecure.Center()
topSecure.Show(True) # Show the frame.
secureApp.MainLoop()
答案 0 :(得分:0)
我可能在这里误解了这个问题,但你编的是platform.node()
而不是输入,不应该读取if语句:
if (str(serialNumberValue.encode("base64"))) == encodedValue:
print "ok"
topSecure.Destroy()