我一直在学习pyi中的gui。但我不知道如何将stringvar转换为int,以便我可以使用。 我做了这个分数计算程序。
from tkinter import *
root = Tk()
root.geometry('300x300')
labelFrame = Frame(root)
labelFrame.pack(side='top')
topFrame = Frame(root)
bottomFrame = Frame(root)
topFrame.pack()
bottomFrame.pack(side='bottom')
l1 = Label(labelFrame, text='adi').pack(side='left')
l2 = Label(labelFrame, text=' appa ').pack(side='left')
l3 = Label(labelFrame, text=' amma').pack(side='left')
class adi:
def enter(self):
self.entry = Entry(root, width=5)
self.entry.pack(side='left')
self.entry = StringVar(self.entry)
self.entry = int(self.entry)
def submit(self):
self.middleFrame = Frame(root)
self.middleFrame.pack()
if self.entry < 250:
self.eentry = StringVar(self.entry)
self.label = Label(middleFrame, text=eentry,
width=6).pack(side='left')
else:
self.label1 = Label(middleFrame, text='your out',
width=6).pack(side='left')
adi = adi()
button = Button(topFrame, text=' enter ', width=5,
command=adi.enter()).pack(side='left')
button2 = Button(topFrame, text='enter 2', width=5,
command=adi.enter()).pack(side='left')
button3 = Button(topFrame, text='enter 3', width=5,
command=adi.enter()).pack(side='left')
button4 = Button(bottomFrame, text='submit', width=5,
command=adi.submit()).pack(side='bottom')
root.mainloop()
但是当我跑这个时,
C:\Users\adithya\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/adithya/Desktop/python/Adithya.py
Traceback (most recent call last):
File "C:/Users/adithya/Desktop/python/Adithya.py", line 37, in <module>
button = Button(topFrame, text=' enter ', width=5, command=adi.enter()).pack(side='left')
File "C:/Users/adithya/Desktop/python/Adithya.py", line 23, in enter
self.entry = int(self.entry)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'StringVar'
Process finished with exit code 1
这发生了。 请帮我介绍如何将stringvar转换为int