Python无法使.get函数起作用

时间:2016-10-02 19:09:08

标签: python tkinter

潜伏在论坛周围,但似乎无法使get()函数正常工作,它会一直返回它没有定义。有人可以指出我做错了吗?

 #include <stdio.h>
    FILE *fp;

    //For loop, which allows up to 4 entries.
    int main(void) {
        int i;

        fp = fopen("csis.txt", "w");
        for (i = 1; i <= 4; ++i) {
            calculateBMI();
        }
        fclose(fp);
        return 0;
    }

    //Function that calculates the BMI of the Input.
    double calculateBMI(int weightInPounds, int heightInInches) {
        double BMI;

        BMI = weightInPounds * 703 / heightInInches * heightInInches;

        //If BMi is less then 18.5 print this.
        if (BMI < 18.5) {
            printf("Your BMI is %d, you are underweight.", BMI);
            fprintf(fp, "Your BMI is %d, you are underweight.", BMI);
        }
        //if BMI is between 18.5 and less then 25 print this.
        else if (BMI > 18.5 & BMI < 25) {
            printf("Your BMI is %d, you are Normal.", BMI);
            fprintf(fp, "Your BMI is %d, you are Normal.", BMI);
        }
        //if BMI is greater then 25 and less then 30 print this.
        else if (BMI > 25 & BMI < 30) {
            printf("Your BMI is %d, you are Overweight.", BMI);
            fprintf(fp, "Your BMI is %d, you are Overweight.", BMI);
        }
        //if BMI is greater then 30 print this.
        else (BMI > 30) {
            printf("Your BMI is %d, you are Obese.", BMI);
            fprintf(fp, "Your BMI is %d, you are Obese.", BMI);
        }

        //Asks user for input weight in pounds.
        printf("What is your weight in pounds?");
        fprintf(fp, "What is your weight in pounds?");
        scanf("%d\n", weightInPounds);
        fscanf(fp, "%d\n", weightInPounds);

        // Asks user for input height in inches.
        printf("What is your height in inches?");
        fprintf("What is your height in inches?");
        scanf("%d\n", heightInInches);
        fscanf(fp, "%d\n", heightInInches);

        getchar(0);
        return (0);
    }

2 个答案:

答案 0 :(得分:2)

grid方法返回 None。这会为None分配entry值。

相反,您希望将Entry的实例分配给entry,然后修改网格:

entry = Entry(master=None, width = 8, bg='grey')
entry.grid(row=2, column = 2)

答案 1 :(得分:1)

entry = Entry(master=None, width = 8, bg='grey').grid(row=2, column = 2)

这会将entry分配给.grid()方法的返回值,但.grid()不会返回任何内容,因此entry将为无。

你应该写

entry = Entry(master=None, width=8, bg='grey')
entry.grid(row=2, column=2)

对所有其他小部件执行相同的操作。