最近我一直在研究一个代码,并因为这个错误而卡住了好几天。基本上,该程序会计算您每天必须摄入多少卡路里。我必须从条目中获取输入,但我不知道如何将该输入(默认为字符串)转换为浮点数以开始使用数字。我在 Tkinter 中使用 Python 3。
这是代码:
from tkinter import *
root = Tk()
root.geometry("1000x500")
root.resizable(FALSE, FALSE)
root.title("BMI Calculator")
def calc(args):
def BMI_temp(args):
print(str(boyage))
BMI = IntVar()
BMI = 66.5 + (13.75 * float(boykg)) + (5.003 * float(boycm)) - (6.755 * float(boyage))
bmi_temp = Label(root, text="This is how many calories you have to eat if you have a non-active life: " + str(float(BMI)))
bmi_temp.grid(row=3, sticky=W)
def boy_age_fnct(args):
boy_age_entry.focus_set()
boy_cm_entry.delete(0, "end")
boy_age.grid(row=2, sticky=W)
boy_age_entry.grid(row=2, column=1)
boy_age_entry.bind("<Return>", BMI_temp)
def boy_cm_fnct(args):
boy_cm_entry.focus_set()
boy_kg_entry.delete(0, "end") …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,但我不知道为什么在打印矢量时会显示数字“ 1 2 3 4”,最后显示“%”,例如“ 1 2 3 4%”
我会给你一个代码示例
#include <stdio.h>
#include <vector>
using namespace std;
int n;
vector<int> soldati;
int main(){
scanf ("%d", &n);
for (int i = 1; i <= n; i++){
soldati.push_back(i);
}
for (int i = 0; i < soldati.size(); i++){
printf("%d ", soldati[i]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
而这里是什么节目,当我运行它。
我提供的链接是因为我无法发布照片。
我正在尝试调用一个如下所示的函数
func customTextField(placeholder: String, text: Binding<String>) -> some View {
ZStack(alignment: .leading){
if text.isEmpty{
VStack {
Text(placeholder)
.font(.system(size: 14))
.fontWeight(.regular)
.foregroundColor(Color(red: 0.5803921568627451, green: 0.5803921568627451, blue: 0.5803921568627451))
.padding()
if placeholder == "Your message type here..."{
Spacer()
}
}
}
TextField("", text: text)
.font(.system(size: 14))
.foregroundColor(.black)
.padding()
}
.frame(height: placeholder == "Your message type here..." ? 170 : 54)
.background(RoundedRectangle(cornerRadius: 16).stroke(text.isEmpty ? Color.clear : Color("orange")))
.background(Color.white)
.cornerRadius(16)
}
Run Code Online (Sandbox Code Playgroud)
但因为text
是Binding<String>
我不能使用.isEmpty()
它。我不想为它创建另一个结构视图。对此最好的方法是什么?