[collapse=3.2 代码实现]
[code=python]
import tkinter as tk
import tkinter.messagebox
import random
def clear_leading_zero(s):
s1 = ''
discriminator = False
for i in range(len(s)):
if (s != '0') and (discriminator is False):
discriminator = True
if discriminator is True:
s1 = s1+s
return s1
if profit_injury_free != 0:
if profit_hp != 0:
str_print = str_print+'1躲闪等级='+str(round(profit_injury_free / profit_hp, 2))+'耐力\n'
if profit_armor != 0:
str_print = str_print+'1躲闪等级='+str(round(profit_injury_free / profit_armor, 1))+'护甲\n'
if profit_block_value != 0:
str_print = str_print+'1躲闪等级='+str(round(profit_injury_free / profit_block_value, 1))+'格挡值\n'
var_print.set(str_print)
def run():
str_hp = clear_leading_zero(var_hp.get())
for i in range(len(str_hp)):
if (str_hp < '0') or (str_hp > '9'):
tk.messagebox.showwarning(title='waring', message='请保证输入的血量为正整数且没有多余空格!')
return
if len(str_hp) != 5:
tk.messagebox.showwarning(title='waring', message='请保证输入的血量在1.5W-2.2W之间!')
return
hp = int(str_hp)
if (hp < 15000) or (hp > 22000):
tk.messagebox.showwarning(title='waring', message='请保证输入的血量在1.5W-2.2W之间!')
return
str_armor = clear_leading_zero(var_armor.get())
for i in range(len(str_armor)):
if (str_armor < '0') or (str_armor > '9'):
tk.messagebox.showwarning(title='waring', message='请保证输入的护甲为正整数且没有多余空格!')
return
if len(str_armor) != 5:
tk.messagebox.showwarning(title='waring', message='请保证输入的护甲在1.5W-3.5W之间!')
return
armor = int(str_armor)
if (armor < 15000) or (armor > 35000):
tk.messagebox.showwarning(title='waring', message='请保证输入的护甲在1.5W-3.5W之间!')
return
str_block_value = clear_leading_zero(var_block_value.get())
for i in range(len(str_block_value)):
if (str_block_value < '0') or (str_block_value > '9'):
tk.messagebox.showwarning(title='waring', message='请保证输入的格挡值为正整数且没有多余空格!')
return
if (len(str_block_value) <= 2) or (len(str_block_value) >= 5):
tk.messagebox.showwarning(title='waring', message='请保证输入的格挡值在200-1500之间!')
return
block_value = int(str_block_value)
if (block_value < 200) or (block_value > 1500):
tk.messagebox.showwarning(title='waring', message='请保证输入的格挡值在200-1500之间!')
return
str_injury_free = clear_leading_zero(var_injury_free.get())
count_point = 0
injury_free = 0
for i in range(len(str_injury_free)):
if ((str_injury_free < '0') or (str_injury_free > '9')) and (str_injury_free != '.'):
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值为正整数,或正整数带最多两位小数,且没有多余空格!')
return
if str_injury_free == '.':
count_point = count_point + 1
if count_point >= 2:
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值为正整数,或正整数带最多两位小数,且没有多余空格!')
return
if count_point == 0:
if (len(str_injury_free) < 1) or (len(str_injury_free) > 3):
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值在0-100之间!')
return
injury_free = int(str_injury_free) * 1.0
if (injury_free < 0) or (injury_free > 100):
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值在0-100之间!')
return
if count_point == 1:
str_int = ''
str_float = ''
discriminator = False
for i in range(len(str_injury_free)):
if str_injury_free == '.':
discriminator = True
continue
if discriminator is False:
str_int = str_int+str_injury_free
else:
str_float = str_float+str_injury_free
if len(str_int) > 3:
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值在0-100之间!')
return
injury_free = int(str_int)
if (injury_free < 0) or (injury_free > 100):
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值在0-100之间!')
return
if len(str_float) > 2:
tk.messagebox.showwarning(title='waring', message='请保证输入的硬免值的小数部分最多只有两位!')
return
injury_free = injury_free+float('0.'+str_float)
model = list_box.curselection()
if model == ():
tk.messagebox.showwarning(title='waring', message='尚未选择挨打模型!')
return