GUI Tkinter中的TypeError:ask_StableVL()缺少1个必需的位置参数:“enter”

2024-06-13 05:49:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写通过GUI输入索引值的代码:

import tkinter as tk
import tkinter.messagebox
#from tkinter import *
from PIL import Image, ImageTk  #To display the image of the formulas of the methods
from tkinter.filedialog import askopenfile 

root3 = tk.Tk()
root3.geometry('200x300') 
info2=tk.Label(root3,text='Enter index of last head value before initiation slug test',anchor='e')
info2.pack()

#Parameter
par = ('Index of stable level')
def ask_stableLvl(enter):
    global stableLvl
    stableLvl =  float(enter['Index of stable level'].get()) 
    print(stableLvl)
#stableLvl = int(input('Enter index of last head value before initiation slug test: '))
def fill(stableLvl):
    dic = {}
    row2 = tk.Frame(root3)
    lab2 = tk.Label(row2, width=15, text=stableLvl, anchor='w')
    ent2 = tk.Entry(row2)      
    row2.pack(side=tk.TOP,fill=tk.X,padx=2,pady=2)
    lab2.pack(side=tk.LEFT)
    ent2.pack(side=tk.RIGHT, expand=tk.YES,fill=tk.X)
    dic[stableLvl] = ent2
    return dic
#
if __name__ == '__main__':
    ent2 = fill(stableLvl)
save_button = tk.Button(root3)
save_button.configure(text='Save', command=ask_stableLvl())
save_button.pack()
root3.mainloop()

但我得到一个类型错误:不支持的操作数类型保存按钮。配置(text='save',command=ask\u stablevl())

有什么问题吗


Tags: ofthetextfromimporttkintersavefill
1条回答
网友
1楼 · 发布于 2024-06-13 05:49:32

正如类型错误中所述:

不支持+的操作数类型:'int'和'str' ,

你不能将整数和字符串相加,即使你想把它们放在一起,它也会把它们当作一个整数,所以它会尝试将两者相加

您应该尝试使用str()

lab2 = tk.Label(row2, width=15, text=str(stableLvl) + ": ", anchor='w')

我不是百分之百肯定,它以前对我有用

相关问题 更多 >