已有183人关注
如何让GUI界面与方法分别用两个类写
发表在Python图书答疑 2021-11-22 《Python GUI设计tkinter从入门到实践》第10章 菜单组件
是否精华
版块置顶:
from tkinter import *
from tkinter.ttk import *
class UI(Frame):
    def __init__(self,master):
        super().__init__(master)
        self.master=master
        self.grid()
        self.create()
        self.bind()
    def create(self):
        self.mon=IntVar()
        self.mon.set(0)
        self.combobox=Combobox(self,value=tuple(range(13)),textvariable=self.mon)
        self.combobox.grid(row=0,column=0)
        self.combobox.bind('<<ComboboxSelected>>',self.setdate)
        self.entry=Entry(self)
        self.entry.grid(row=1,column=1)

    def setdate(self,a=None):
        temp=self.combobox.get()
        if int(temp)==2:
            self.entry.insert(0,'33')


if __name__ == '__main__':
    win=Tk()
    win.geometry('400x300')
    ui=UI(win)
    win.mainloop()

请问下 上面代码UI类里最后的一个setdate函数可以再另外一个类里实现吗 

比如下面 在定义一个类装UI上函数的方法

class Method():
    def setdate(self,a=None):
        temp=self.combobox.get()
        if int(temp)==2:
            self.entry.insert(0,'33')


分享到:
精彩评论 2
小禾斗
学分:7318 LV13
TA的每日心情
奋斗
2017-04-21 14:00:25
2021-11-23
沙发

https://mp.weixin.qq.com/s/Q_FjBulV18J5wDfoJxoXgg

game99258
学分:2266 LV10
2022-08-09
板凳

可以

首页上一页 1 下一页尾页 2 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照