python - 如何在 python 中使用 tkinter 实现 mvc
问题描述
from Tkinter import *
class Model_Adder(object):
def __init__(self):
a=int(self.entry.get())
b=int(self.entry1.get())
selfsum=a+b
class View_Add(object):
def loadView(self):
quitButton = Button(self.frame,text = 'Quit', command=
self.vc.quitButtonPressed).grid(row = 0,column = 0)
addButton = Button(self.frame,text = "Add", command =
self.vc.addButtonPressed).grid(row = 0, column = 1)
entry = Entry(self.frame,textvariable = self.entry_text).grid(row
= 1, column = 0, columnspan = 3, sticky = EW)
label = Label(self.frame,textvariable =
self.vc.label_text).grid(row = 2, column = 0, columnspan
= 3, sticky = EW)
def __init__(self,vc):
self.frame=Frame()
self.frame
self.entry = Entry(self.window)
self.entry1=Entry(self.window)
self.label1=Label(self.window,text='sum is')
label2.configure(self.window,text=sum)
self.label1.grid(row=3,column=0,columnspan=3,sticky=E)
self.label2.grid(row=3,column=5,columnspan=3,sticky=E)
self.entry.grid(row=1, column=0, columnspan=3, sticky=W+E)
self.entry1.grid(row=2, column=0, columnspan=3, sticky=W+E)
self.button.grid(row=4, column=0)
self.button1.grid(row=4, column=0)
class contr(object): def init (self,model): self.model=model self v=View_Adder() v.button = Button(window, text="add", command=a.add) v.button1=Button (window, text="quit", command=window.quit) self.label2(window,text='0')
def main():
root=tk.Tk()
a=Adder()
controller=contr()
view=View_Add(root,controller
root.title('Test')
解决方案
推荐阅读
- android - Cordova - Android - 为什么 Android 操作系统会删除 WebSQL 和本地存储数据?
- javascript - 将输入 ID 更改为错误地更新状态
- go - 反向代理意外 EOF 读取请求正文
- java - Why sendKeys() in Windows IE 11 no longer persists after upgrading to Selenium Java 3.14.0?
- android - 如何使用 animatorSet 更改视图的背景颜色
- swift - 如何使用 Vapor 3 在 PostgreSQL 中存储 Swift 类型(日期、字典等)?
- c# - 参数异常 - 路径不是合法形式?
- sql - 通过外键进行冗余以允许更简单的常见查询?
- regex - 正则表达式将匹配字符串中的所有单词
- c# - MQTTnet 客户端发布