小编Pak*_*Pak的帖子

tkinter,如何获取 Entry 小部件的值?

如果利润率具有特定值 (0.23),我正在尝试为用户提供计算其预计销售利润的可能性。用户应该能够输入任何值作为预计销售额:

from tkinter import *

root = Tk()

margin = 0.23
projectedSales = #value of entry
profit = margin * int(projectedSales)

#My function that is linked to the event of my button
def profit_calculator(event):
    print(profit)


#the structure of the window
label_pan = Label(root, text="Projected annual sales:")
label_profit = Label(root, text="Projected profit")
label_result = Label(root, text=(profit), fg="red")

entry = Entry(root)

button_calc = Button(root, text= "Calculate", command=profit_calculator)
button_calc.bind("<Button-1>", profit_calculator)

#position of the elements on the window
label_pan.grid(row=0)
entry.grid(row=0, column=1)
button_calc.grid(row=1)              
label_profit.grid(row=2) …
Run Code Online (Sandbox Code Playgroud)

user-interface tkinter python-3.x

9
推荐指数
1
解决办法
5万
查看次数

标签 统计

python-3.x ×1

tkinter ×1

user-interface ×1