我在尝试使用类在 tkinter 中使用组合框创建简单计算时遇到问题。对我来说,这很棘手,很难理解!希望你能帮我解决这个问题。
提前致谢。
赫克托。
这是我的代码:
from Tkinter import *
import ttk
from ttk import Combobox
root= Tk()
root.minsize(550,450)
root.maxsize(560,460)
root.title('myAPP')
class Calculation:
def __init__(self, parent):
self.parent = parent
self.Value1()
self.Value2()
self.Result()
Label(self.parent,text='Num 1').grid(column=2, row=5,sticky=W,pady=3)
Label(self.parent,text='Num 2').grid(column=2, row=6,sticky=W,pady=3)
Label(self.parent,text='result').grid(column=9,row=9,sticky=W,pady=3)
self.msg =Label(self.parent,text='Sum of 2 number')
self.msg.grid(row=3,column=1,columnspan=2)
self.Button =Button(text='Calculate',width=8,command =self.Result)
self.Button.grid(row=9,column=2,padx=2,pady=3)
def Value1(self):
self.field1 = StringVar()
self.field1 = ttk.Combobox(self.parent, textvariable= self.field1)
self.field1['values'] = ('5', '6', '7')
self.field1.grid(column=3, row=5)
def Value2(self):
self.field2 = StringVar()
self.field2 = ttk.Combobox(self.parent, textvariable=self.field2)
self.field2['values'] = ('1', '2', '3')
self.field2.grid(column=3, row=6)
def Result(self):
self.entry = StringVar()
self.entry = ttk.Entry(self.parent, textvariable = self.entry)
#self.entry = field1 + field2 ----> Here is the problem I have!
self.entry.grid(column=3, row=9)
#End Code
if __name__ == '__main__':
app = Calculation (root)
root.mainloop()