首页上一页 1 下一页尾页 2 条记录 1/1页
如何让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')

购物车
发表新帖
立即签到








