嗨,我有A str'对象没有属性' get' Python-tkinter中的问题
它行不通 我希望它获得一个数字,然后单击这些按钮bellow,然后在消息框中获取结果,该怎么办?
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
win=Tk()
#here is my problem
def household():
global s
global math
math="multiply"
x=int(E.get())
s=(x/100)*500
b="your bill is:"+str(s)
messagebox.showinfo("result",b)
def commercial():
global s
x=int(E.get())
if x<=4000000:
s=(x/100)*750
household()
commercial()
E=Entry(win,bg="#87CEFA")
b1=Button(win,text="Household",bg="#4169E1",command=household)
b3=Button(win,text="commercial",bg="#4169E1",command=commercial)
E.place(x=100,y=85,width=100,height=20)
b1.place(x=100,y=165,width=100,height=30)
b3.place(x=150,y=165,width=100,height=30)
it doesn't work
i want it to get a number then click those button bellow and then get the result in the message box what should i do?!
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
win=Tk()
#here is my problem
def household():
global s
global math
math="multiply"
x=int(E.get())
s=(x/100)*500
b="your bill is:"+str(s)
messagebox.showinfo("result",b)
def commercial():
global s
x=int(E.get())
if x<=4000000:
s=(x/100)*750
household()
commercial()
E=Entry(win,bg="#87CEFA")
b1=Button(win,text="Household",bg="#4169E1",command=household)
b3=Button(win,text="commercial",bg="#4169E1",command=commercial)
E.place(x=100,y=85,width=100,height=20)
b1.place(x=100,y=165,width=100,height=30)
b3.place(x=150,y=165,width=100,height=30)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在调用
homepor()
和commercial()
在定义E之前,因为您正在进行通配符导入(tkinter Import *
)您正在从tkinter导入常量e
,该>定义为字符串“ e”。解决方案是:
导入TKINTER的通配符导入TKINTER作为TK
,然后使用tk。
作为所有TKINTE对象的前缀(tk.entry) (...)
,tk.button(...)
等)You're calling
household()
andcommercial()
before you define E. Because you are doing a wildcard import (from tkinter import *
) you're importing the constantE
from tkinter, which is defined as the string "e".The solution is:
import tkinter as tk
and then usetk.
as a prefix for all tkinter objects (tk.Entry(...)
,tk.Button(...)
, etc)