我是Tkinter OOP的新手,正在尝试开发一个包含3个窗口的应用程序(我使用过Toplevel())
。
MainPage
plan_but
应该能够在ForGeeks页面上显示num_events
,并且只要num_events
发生变化就可以进行更改。
我尝试过text = text = str(self.show_geek())
,但是它没有改变,运行代码时,极客窗口会打开。
有人可以帮我吗?
from tkinter import *
from re import findall
from web_doc_downloader import download
# ...
class MainPage:
def __init__(self):
self.mainwindow = Tk()
# self.geek_obj = ForGeeks(Toplevel(self.mainwindow))
self.logo = PhotoImage(file='logo.gif')
background_width = self.logo.width()
background_height = self.logo.height()
# resize the window
self.mainwindow.geometry('%sx%s' % (background_width, background_height))
# Canvas to put image in
self.canvas = Canvas(width=background_width, height=background_height)
self.canvas.pack(side=TOP, fill=BOTH, expand=YES)
self.canvas.create_image(0, 0, image=self.logo, anchor=NW)
#Print plans button
self.plan_but = Button(self.canvas, text = str(self.show_geek()))
self.plan_but.place(height = 40, relwidth = 0.25, rely = 0.05, relx = 0.375)
# ...
def show_geeks(self):
self.geekwindow = Toplevel(self.mainwindow)
self.geekapp = ForGeeks(self.geekwindow)
return self.geekapp.num_events
class ForGeeks:
def __init__(self, geek_app, bg = 'blue'):
self.geek_app = geek_app
self.geek_app['bg']= bg
self.title = Label(self.geek_app, text = 'Events for Geeks' , font = ('Times',20, 'bold'), height = 3, width = 50, bg=bg)
self.title.pack(expand = YES, anchor = N)
self.event_list = Checkbar(self.geek_app, geek, bg = bg)
self.event_list.pack(side=TOP)
self.num_events = self.events_count()
def events_count(self):
return(self.event_list.count())