我想知道是否有更好的寫作方法。下面陳述的當前代碼有效。我只是想知道是否有更好的方法。嵌套的IF-ELIF語句
這是用於驗證。因此,if語句檢查所有必填字段,如果它們可以接受,那麼它將進入執行代碼。這個問題開始,因爲在輸入字段
self.text_fmax
沒有被接受爲整數。所以這個特定領域中,首先檢查是否爲空則忽略不計,如果不是則該值必須是整數0 180之間和
def call_back(self):
if len(self.text_n.get()) == 0:
tkMessageBox.showinfo("Mandatory Information", "Please input an integer value for Number of Tessellations Cells")
elif len(self.text_id.get()) == 0:
tkMessageBox.showinfo("Mandatory Information", "Please input an integer value for Tessellation Identifier")
elif len(domain_container) == 0:
tkMessageBox.showinfo("Mandatory Information", "Please input Domain")
elif len(self.text_fmax.get()) != 0:
a = int(self.text_fmax.get())
if a < 0 or a > 180:
tkMessageBox.showinfo("Incorrect Value", "Face Flatness should be less than 180")
elif len(filename4) == 0:
tkMessageBox.showinfo("Mandatory Information", "Please input Output File Name")
else:
self.execute_neper_code()
elif len(filename4) == 0:
tkMessageBox.showinfo("Mandatory Information", "Please input Output File Name")
else:
self.execute_neper_code()
如果這段代碼正在工作,那麼這個問題似乎更適合[Code Review StackExchange site](http://codereview.stackexchange.com)。 – ShadowRanger
@ShadowRanger:謝謝你,我從來不知道這樣的網站存在。我仍然是Pyton2.7的新手。我也會在那裏發帖。謝謝:) –