如何将Calendar(CalendarWidget.py)的功能合并到主程序(GUIframe.py)中?

时间:2016-04-16 18:54:38

标签: python tkinter calendar

我有两个程序,一个显示日历,用户可以在其中选择他的月份,然后查看该月的日历。其次,该程序有三个框架和一个按钮“日历”。我该怎么办,当点击'GUIframe.py'程序的“日历”按钮时,'CalendarWidget.py'的功能才会生效?

- > GUIFrame

taskHandler :: Channel -> MVar () -> (Message, Envelope) -> IO ()

...

consumeMsgs ch "tasks" Ack (taskHandler ch lock)

---> CalendarWidget.py

from tkinter import *

root = Tk()
frame = Frame(root)
frame.pack()

def Bprint():
    print("CLICKED")

def Bprint1():
    print("Clicked Blue!")


bottomframe1=Frame(root)
bottomframe1.pack( side = BOTTOM )
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )


redbutton = Button(frame, text="Red", fg="red")
redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")
greenbutton.pack(side = RIGHT)

bluebutton = Button(frame, text="Blue", fg="blue", command=Bprint1)
bluebutton.pack(side = LEFT)

blackbutton = Button(bottomframe, text="Black", fg="black", command=Bprint)
blackbutton.pack( side = BOTTOM)

cal_b= Button(bottomframe1, text="Calendar", fg="black")
cal_b.pack(side=BOTTOM)


root.mainloop()

1 个答案:

答案 0 :(得分:0)

您需要将command绑定到文件中的按钮,看起来要调用test,这样您就可以执行from CalendarWidget import test然后执行

 cal_b= Button(bottomframe1, text="Calendar", fg="black", command = test)

虽然您可能不希望在整个地方都有额外的Tk()个实例,因此您应该使用Toplevel小部件作为日历。