1

in-datesユーザーがいくつかを選択する必要があるUIを実行していますout-dates. In-dates工場に注文が入ったとき、それout-datesを受け取りたいとき。

私が抱えている問題は、1 つをクリックしin-dateてカレンダーから日付を選択すると、すべてがin-datesこの同じ日付で満たされることです。

ここに画像の説明を入力

コードは長く見えますが、そうではありません。コードの半分以上はカレンダー コード (次のコードからclass TkcClendar下まで) であり、私を助けるためにそれを見る必要さえありません。

# -*- coding: utf-8 -*-
import os
from Tkinter import *
import Image
import ImageTk
import tkFileDialog
import xlrd
import csv
from tkMessageBox import *
from win32com.client import Dispatch
import datetime
import time
import calendar

year = time.localtime()[0]
month = time.localtime()[1]
day =time.localtime()[2]
strdate = (str(year) +  "/" + str(month) + "/" + str(day))

fnta = ("Helvetica", 10)
fnt = ("Helvetica", 10)
fntc = ("Helvetica", 10, 'bold')

lang="span"

if lang == "span":
    #Spanish Options
    strtitle = "Calendario"
    strdays= "Do  Lu  Ma  Mi  Ju  Vi  Sa"
    dictmonths = {'1':'Ene','2':'Feb','3':'Mar','4':'Abr','5':'May',
    '6':'Jun','7':'Jul','8':'Ago','9':'Sep','10':'Oct','11':'Nov',
    '12':'Dic'}
else :
    #English Options
    strtitle = "Calendar"
    strdays = "Su  Mo  Tu  We  Th  Fr  Sa"
    dictmonths = {'1':'Jan','2':'Feb','3':'Mar','4':'Apr','5':'May',
    '6':'Jun','7':'Jul','8':'Aug','9':'Sep','10':'Oct','11':'Nov',
    '12':'Dec'}

class Planificador(Frame):
    def __init__(self,master):
        Frame.__init__(self, master)
        self.master = master
        self.initUI()

    def initUI(self):
        self.master.title("Planner")
        self.frameOne = Frame(self.master)
        self.frameOne.grid(row=0,column=0)
        self.frameTwo = Frame(self.master)
        self.frameTwo.grid(row=0, column=1)

        self.frameThree = Frame(self.master)
        self.frameThree.grid(row=0, column=2)
        self.frameFour = Frame(self.master)
        self.frameFour.grid(row=1,column=0)
        self.frameFive = Frame(self.master)
        self.frameFive.grid(row=1, column=1)
        self.frameSix = Frame(self.master)
        self.frameSix.grid(row=1, column=2)
        self.frameSeven = Frame(self.master)
        self.frameSeven.grid(row=2,column=0)
        self.frameEight = Frame(self.master)
        self.frameEight.grid(row=2, column=1)
        self.frameNine = Frame(self.master)
        self.frameNine.grid(row=2, column=2)

        self.start_date_menu()

    def start_date_menu(self):
        self.date_num = raw_input("Number of dates?")
        self.n = 1

        self.textoprioridad = Label(self.frameFour, text = "Day in", justify="center")
        self.textoprioridad.grid(row=self.n, column=2)
        self.lotestext = Label(self.frameFour, text = "Day out", justify="center")
        self.lotestext.grid(row=self.n, column=3, padx=(10,0))

        self.textoprioridad = Label(self.frameSix, text = "Day in", justify="center")
        self.textoprioridad.grid(row=self.n, column=2)
        self.lotestext = Label(self.frameSix, text = "Day out", justify="center")
        self.lotestext.grid(row=self.n, column=3, padx=(10,0))

        self.date_var1 = StringVar()
        self.date_var1.set(" day in ")
        self.date_var2 = StringVar()
        self.date_var2.set(" day out")

        while self.n <= int(self.date_num):
            if(int(self.n) % 2) != 0:
                self.fechallegada = Button(self.frameFour, textvariable=self.date_var1, command=lambda:self.fnCalendar(self.date_var1))
                self.fechallegada.grid(row=self.n+1, column=2)
                self.fechasalida = Button(self.frameFour, textvariable=self.date_var2, command=lambda:self.fnCalendar(self.date_var2))
                self.fechasalida.grid(row=self.n+1, column=3)

            else:
                self.fechallegada = Button(self.frameSix, textvariable=self.date_var1, command=lambda:self.fnCalendar(self.date_var1))
                self.fechallegada.grid(row=self.n+1, column=2)
                self.fechasalida = Button(self.frameSix, textvariable= self.date_var2, command=lambda:self.fnCalendar(self.date_var2))
                self.fechasalida.grid(row=self.n+1, column=3)

            self.n += 1
        self.anadirpiezas = Button(self.frameEight, text="add more", command=self.addpieza, width=10)
        self.anadirpiezas.grid(row=0, column=3, pady=(10,10))

    def addpieza(self):
            if(int(self.date_num) % 2) == 0:
                self.fechallegada = Button(self.frameFour, textvariable=self.date_var1, command=lambda:self.fnCalendar(self.date_var1))
                self.fechallegada.grid(row=int(self.date_num)+1, column=2)
                self.fechasalida = Button(self.frameFour, textvariable= self.date_var2, command=lambda:self.fnCalendar(self.date_var2))
                self.fechasalida.grid(row=int(self.date_num)+1, column=3)
            else:
                self.fechallegada = Button(self.frameSix, textvariable=self.date_var1, command=lambda:self.fnCalendar(self.date_var1))
                self.fechallegada.grid(row=int(self.date_num)+1, column=2)
                self.fechasalida = Button(self.frameSix, textvariable= self.date_var2, command=lambda:self.fnCalendar(self.date_var2))
                self.fechasalida.grid(row=int(self.date_num)+1, column=3)

            self.date_num = int(self.date_num)+1

    def fnCalendar(self, datebar):
        tkCalendar(self.master, year, month, day, datebar)

class tkCalendar :
  def __init__ (self, master, arg_year, arg_month, arg_day,
       arg_parent_updatable_var):
    self.update_var = arg_parent_updatable_var
    top = self.top = Toplevel(master)
    top.title("Eleccion de fecha")
    try : self.intmonth = int(arg_month)
    except: self.intmonth = int(1)
    self.canvas =Canvas (top, width =200, height =220,
      relief =RIDGE, background ="#ece9d8", borderwidth =0)
    self.canvas.create_rectangle(0,0,303,30, fill="#ece9d8",width=0 )
    self.canvas.create_text(100,17, text="Elige una fecha",  font=fntc, fill="#BA1111")
    stryear = str(arg_year)

    self.year_var=StringVar()
    self.year_var.set(stryear)
    self.lblYear = Label(top, textvariable = self.year_var,
        font = fnta, background="#ece9d8")
    self.lblYear.place(x=85, y = 30)

    self.month_var=StringVar()
    strnummonth = str(self.intmonth)
    strmonth = dictmonths[strnummonth]
    self.month_var.set(strmonth)

    self.lblYear = Label(top, textvariable = self.month_var,
        font = fnta, background="#ece9d8")
    self.lblYear.place(x=85, y = 50)
    #Variable muy usada
    tagBaseButton = "Arrow"
    self.tagBaseNumber = "DayButton"
    #draw year arrows
    x,y = 40, 43
    tagThisButton = "leftyear"
    tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
    self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
    x,y = 150, 43
    tagThisButton = "rightyear"
    tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
    self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
    #draw month arrows
    x,y = 40, 63
    tagThisButton = "leftmonth"
    tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
    self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
    x,y = 150, 63
    tagThisButton = "rightmonth"
    tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
    self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
    #Print days
    self.canvas.create_text(100,90, text=strdays, font=fnta)
    self.canvas.pack (expand =1, fill =BOTH)
    self.canvas.tag_bind ("Arrow", "<ButtonRelease-1>", self.fnClick)
    self.canvas.tag_bind ("Arrow", "<Enter>", self.fnOnMouseOver)
    self.canvas.tag_bind ("Arrow", "<Leave>", self.fnOnMouseOut)
    self.fnFillCalendar()

  def fnCreateRightArrow(self, canv, x, y, strtagname):
    canv.create_polygon(x,y, [[x+0,y-5], [x+10, y-5] , [x+10,y-10] ,
        [x+20,y+0], [x+10,y+10] , [x+10,y+5] , [x+0,y+5]],
        tags = strtagname , fill="black", width=0)

  def fnCreateLeftArrow(self, canv, x, y, strtagname):
    canv.create_polygon(x,y, [[x+10,y-10], [x+10, y-5] , [x+20,y-5] ,
        [x+20,y+5], [x+10,y+5] , [x+10,y+10] ],
        tags = strtagname , fill="black", width=0)


  def fnClick(self,event):
    owntags =self.canvas.gettags(CURRENT)
    if "rightyear" in owntags:
    intyear = int(self.year_var.get())
    intyear +=1
    stryear = str(intyear)
    self.year_var.set(stryear)
    if "leftyear" in owntags:
    intyear = int(self.year_var.get())
    intyear -=1
    stryear = str(intyear)
    self.year_var.set(stryear)
    if "rightmonth" in owntags:
    if self.intmonth < 12 :
        self.intmonth += 1
        strnummonth = str(self.intmonth)
        strmonth = dictmonths[strnummonth]
        self.month_var.set(strmonth)
    else :
        self.intmonth = 1
        strnummonth = str(self.intmonth)
        strmonth = dictmonths[strnummonth]
        self.month_var.set(strmonth)
        intyear = int(self.year_var.get())
        intyear +=1
        stryear = str(intyear)
        self.year_var.set(stryear)
    if "leftmonth" in owntags:
    if self.intmonth > 1 :
        self.intmonth -= 1
        strnummonth = str(self.intmonth)
        strmonth = dictmonths[strnummonth]
        self.month_var.set(strmonth)
    else :
        self.intmonth = 12
        strnummonth = str(self.intmonth)
        strmonth = dictmonths[strnummonth]
        self.month_var.set(strmonth)
        intyear = int(self.year_var.get())
        intyear -=1
        stryear = str(intyear)
        self.year_var.set(stryear)
    self.fnFillCalendar()
  def fnFillCalendar(self):
    init_x_pos = 20
    arr_y_pos = [110,130,150,170,190,210]
    intposarr = 0
    self.canvas.delete("DayButton")
    self.canvas.update()
    intyear = int(self.year_var.get())
    monthcal = calendar.monthcalendar(intyear, self.intmonth)
    for row in monthcal:
    xpos = init_x_pos
    ypos = arr_y_pos[intposarr]
    for item in row:
        stritem = str(item)
        if stritem == "0":
        xpos += 27
        else :
        tagNumber = tuple((self.tagBaseNumber,stritem))
        self.canvas.create_text(xpos, ypos , text=stritem,
            font=fnta,tags=tagNumber)
            xpos += 27
    intposarr += 1
    self.canvas.tag_bind ("DayButton", "<ButtonRelease-1>", self.fnClickNumber)
    self.canvas.tag_bind ("DayButton", "<Enter>", self.fnOnMouseOver)
    self.canvas.tag_bind ("DayButton", "<Leave>", self.fnOnMouseOut)

  def fnClickNumber(self,event):
    owntags =self.canvas.gettags(CURRENT)
    for x in owntags:
    if (x == "current") or (x == "DayButton"): pass
    else :
        strdate = (str(self.year_var.get()) + "/" +
            str(self.intmonth) + "/" +
            str(x))
        self.update_var.set(strdate)
        self.top.withdraw()
  def fnOnMouseOver(self,event):
    self.canvas.move(CURRENT, 1, 1)
    self.canvas.update()

  def fnOnMouseOut(self,event):
    self.canvas.move(CURRENT, -1, -1)
    self.canvas.update()


if __name__ == "__main__":
    root = Tk()
    aplicacion = Planificador(root)
    root.mainloop()

問題は、私は 2 つの作業を行っておらずStringVar、目的のソリューションにはStringVarそれぞれin-dayに1 つが必要であるためout-date、すべてではなく 1 つの日付のみが変更されることですが、これを処理しようとすると問題が発生し、方法がわかりません。さらに、add moreUI に新しい日付を追加するボタンがあります。UI は 2 列構造を維持する必要があります。

私はリストを作成して、StringVar各反復の1つを選択しようとしましたが、うまくいきません:

self.stringList = []                     
for i in xrange(int(self.date_num)*2):
    self.stringList.append(StringVar())
    self.stringList[i].set(" date ")

これを修正する方法はありますか?

4

2 に答える 2

2

以下はPlanificador、独立した日付で希望どおりに機能すると思われるクラスへの変更StringVarです。add moreボタンで日付を動的に追加する機能も機能します。あなたは基本的に s のリストを作成することについて正しい考えを持っていましたStringVar。それに加えて、対応するボタンを保存するために配置します。

あなたのコードで気づいたことの 1 つは、ウィジェットのメソッドに渡されるrowおよびキーワード引数の値が、親フレームではなく、ウィジェットのフレーム自体に相対的であることを理解していないようだったことです。これは、物事のレイアウトを大幅に簡素化できるため 、実際に使用する際の便利な点の 1 つです。columngrid()Frames

作業ダイアログのスクリーンショット


class Planificador(Frame):
    def __init__(self,master):
        Frame.__init__(self, master)
        self.master = master
        self.initUI()

    def initUI(self):
        self.master.title("Planner")
        self.frameOne = Frame(self.master)
        self.frameOne.grid(row=0,column=0)
        self.frameTwo = Frame(self.master)
        self.frameTwo.grid(row=0, column=1)
        self.frameThree = Frame(self.master)
        self.frameThree.grid(row=0, column=2)

        self.frameFour = Frame(self.master)
        self.frameFour.grid(row=1,column=0, sticky=N)
        self.frameFive = Frame(self.master)
        self.frameFive.grid(row=1, column=1)
        self.frameSix = Frame(self.master)
        self.frameSix.grid(row=1, column=2, sticky=N)

        self.frameSeven = Frame(self.master)
        self.frameSeven.grid(row=2,column=0)
        self.frameEight = Frame(self.master)
        self.frameEight.grid(row=2, column=1, sticky=S)
        self.frameNine = Frame(self.master)
        self.frameNine.grid(row=2, column=2)

        self.start_date_menu()

    def start_date_menu(self):
        initial_num_dates = int(raw_input("Number of dates?"))
#        initial_num_dates = 5
        self.DATE_MENU_ROW = 0  # initial date menu grid row
        self.COL_WIDTH = 10  # width of each subcolumn of dates

        for frame in (self.frameFour, self.frameSix):
            self.textoprioridad = Label(frame, text="Day in",
                                        width=self.COL_WIDTH, justify="center")
            self.textoprioridad.grid(row=self.DATE_MENU_ROW, column=0)
            self.lotestext = Label(frame, text="Day out", width=self.COL_WIDTH,
                                   justify="center")
            self.lotestext.grid(row=self.DATE_MENU_ROW, column=1)

        self.dates = [self.create_date_entry(date_index)
                        for date_index in xrange(initial_num_dates)]

        self.anadirpiezas = Button(self.frameEight, text="add more",
                                   command=self.addpieza, width=self.COL_WIDTH)
        self.anadirpiezas.grid(row=0, column=3)

    def addpieza(self):
        self.dates.append(self.create_date_entry(len(self.dates)))

    def create_date_entry(self, date_index):
        # create and return seq of two pairs of button, stringvar for a date
        menu_col = date_index % 2  # left/right column of the date frame
        menu_row = self.DATE_MENU_ROW + date_index/2 + 1
        frame = self.frameSix if menu_col else self.frameFour
        pairs = []
        for col in 0, 1:
            pairs.append(StringVar(value="--------"))
            pairs.append(Button(frame, textvariable=pairs[-1],
                                width=self.COL_WIDTH,
                                command=lambda v=pairs[-1]: self.fnCalendar(v)))
            pairs[-1].grid(row=menu_row, column=col)
        return tuple(pairs)

    def fnCalendar(self, datebar):
        tkCalendar(self.master, year, month, day, datebar)

fnClickNumber()のメソッドも変更して、class tkCalendar常に 2 桁の月と日の値で日付を返すようにしましたが、その使用はオプションです。

    def fnClickNumber(self,event):
        owntags =self.canvas.gettags(CURRENT)
        for x in owntags:
            if (x == "current") or (x == "DayButton"): pass
            else:
                strdate = (str(self.year_var.get()) + "/" +
                           '%02d' % self.intmonth + "/" +
                           '%02d' % int(x))
                self.update_var.set(strdate)
                self.top.withdraw()
于 2013-11-04T22:18:58.873 に答える
1

私は Planificador クラスでのみ変更を行います。

一部の名前を英語に変更します

私はWindowsを使用していないのでオフにしていますfrom win32com.client import Dispatch

最後の瞬間に「最後を削除」ボタンを追加します

# -*- coding: utf-8 -*-
import os
from Tkinter import *
import Image
import ImageTk
import tkFileDialog
import xlrd
import csv
from tkMessageBox import *
#from win32com.client import Dispatch
import datetime
import time
import calendar

#----------------------------------------------------------------------

year  = time.localtime()[0]
month = time.localtime()[1]
day   = time.localtime()[2]
#strdate = (str(year) +  "/" + str(month) + "/" + str(day))
strdate = "%d/%d/%d" % time.localtime()[0:3]

#----------------------------------------------------------------------

fnta = ("Helvetica", 10)
fnt  = ("Helvetica", 10)
fntc = ("Helvetica", 10, 'bold')

#----------------------------------------------------------------------

lang=""

if lang == "span":
    #Spanish Options
    strtitle   = "Calendario"
    strdays    = "Do  Lu  Ma  Mi  Ju  Vi  Sa"
    dictmonths = {
        '1':'Ene','2':'Feb','3':'Mar','4':'Abr','5':'May','6':'Jun',
        '7':'Jul','8':'Ago','9':'Sep','10':'Oct','11':'Nov','12':'Dic'
    }
else :
    #English Options
    strtitle   = "Calendar"
    strdays    = "Su  Mo  Tu  We  Th  Fr  Sa"
    dictmonths = {
        '1':'Jan','2':'Feb','3':'Mar','4':'Apr','5':'May','6':'Jun',
        '7':'Jul','8':'Aug','9':'Sep','10':'Oct','11':'Nov','12':'Dec'
    }

#----------------------------------------------------------------------

class Planificador(Frame):

    def __init__(self,master):
        Frame.__init__(self, master)        
        self.master = master
        self.initUI()

    def initUI(self):
        self.master.title("Planner")

        # subframe for all dates
        self.frame_with_dates = Frame(self.master)
        self.frame_with_dates.grid(row=0,column=0)

        # adding dates to subframe
        self.start_date_menu()

        # adding button "Add more" to main frame
        self.add_button = Button(self.master, text="Add more", command=self.add_more, width=10)
        self.add_button.grid(row=1,column=0, pady=(10,10))

        # adding button "Remove last" to main frame
        self.remove_button = Button(self.master, text="Remove last", command=self.remove_last, width=10)
        self.remove_button.grid(row=2,column=0, pady=(10,10))

    def start_date_menu(self):

        self.date_num = int(raw_input("Number of dates? ")) # get integer

        # left columns
        self.label_day_in_left = Label(self.frame_with_dates, text = "Day in", justify="center")
        self.label_day_in_left.grid(row=0,column=0,padx=(10,10))

        self.label_day_out_left = Label(self.frame_with_dates, text = "Day out", justify="center")
        self.label_day_out_left.grid(row=0,column=1,padx=(10,10))

        # space between columns
        self.label_empty = Label(self.frame_with_dates, text = "|", justify="center")
        self.label_empty.grid(row=0,column=2,padx=(25,25))

        # right columns
        self.label_day_in_right = Label(self.frame_with_dates, text = "Day in", justify="center")
        self.label_day_in_right.grid(row=0,column=3,padx=(10,10))

        self.label_day_out_right = Label(self.frame_with_dates, text = "Day out", justify="center")
        self.label_day_out_right.grid(row=0,column=4,padx=(10,10))

        # list of buttons and variables
        self.dates_buttons = []
        self.dates_vars = []

        # adding button and variable

        self.n = 0 # list starts at 0
        while self.n < self.date_num:

            # add n-th button and variable
            self.add_date_button(self.n)

            # next element  
            self.n += 1

    def add_more(self):
        self.add_date_button(self.date_num)
        self.date_num += 1

    def remove_last(self):
        if self.date_num > 0:
            self.date_num -= 1
            self.dates_buttons[-1][0].destroy()
            self.dates_buttons[-1][1].destroy()
            del self.dates_buttons[-1]
            del self.dates_vars[-1]

    def add_date_button(self, n):

        # default button value
        string_button_in = "day in" 
        string_button_out = "day out"

        # position 

        _row = 1 + n/2  

        if n % 2 == 0:
            _column = 0 # left column
        else:
            _column = 3 # right column

        # adding variable to list - dictionary(in, out)
        self.dates_vars.append({'in':StringVar(), 'out':StringVar()})

        # setting variable text
        self.dates_vars[n]['in'].set("%s (%d)" % (string_button_in, n)) # "day in (number)" 
        self.dates_vars[n]['out'].set("%s (%d)" % (string_button_out, n)) # "day out (number)" 

        # creating buttons
        newbutton_in = Button(self.frame_with_dates, textvariable=self.dates_vars[n]['in'], command=lambda _n=n:self.fnCalendar(self.dates_vars[_n]['in']))
        newbutton_in.grid(row=_row, column=_column, padx=(10,10))

        newbutton_out = Button(self.frame_with_dates, textvariable=self.dates_vars[n]['out'], command=lambda _n=n:self.fnCalendar(self.dates_vars[_n]['out']))
        newbutton_out.grid(row=_row, column=_column+1, padx=(10,10))

        # adding buttons to list
        #self.dates_buttons.append({'in':newbutton_in, 'out':newbutton_out}) # adding as dictionary
        self.dates_buttons.append((newbutton_in,newbutton_out)) # adding as tuple


    def fnCalendar(self, datebar):
        # open window with calendar
        tkCalendar(self.master, year, month, day, datebar)

#----------------------------------------------------------------------

class tkCalendar :

    def __init__(self, master, arg_year, arg_month, arg_day,
            arg_parent_updatable_var):

        self.update_var = arg_parent_updatable_var
        top = self.top = Toplevel(master)
        top.title("Eleccion de fecha")
        try : self.intmonth = int(arg_month)
        except: self.intmonth = int(1)
        self.canvas = Canvas (top, width =200, height =220,
          relief =RIDGE, background ="#ece9d8", borderwidth =0)
        self.canvas.create_rectangle(0,0,303,30, fill="#ece9d8",width=0 )
        self.canvas.create_text(100,17, text="Elige una fecha",  font=fntc, fill="#BA1111")
        stryear = str(arg_year)

        self.year_var=StringVar()
        self.year_var.set(stryear)
        self.lblYear = Label(top, textvariable = self.year_var,
            font = fnta, background="#ece9d8")
        self.lblYear.place(x=85, y = 30)

        self.month_var=StringVar()
        strnummonth = str(self.intmonth)
        strmonth = dictmonths[strnummonth]
        self.month_var.set(strmonth)

        self.lblYear = Label(top, textvariable = self.month_var,
            font = fnta, background="#ece9d8")
        self.lblYear.place(x=85, y = 50)
        #Variable muy usada
        tagBaseButton = "Arrow"
        self.tagBaseNumber = "DayButton"
        #draw year arrows
        x,y = 40, 43
        tagThisButton = "leftyear"
        tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
        self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
        x,y = 150, 43
        tagThisButton = "rightyear"
        tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
        self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
        #draw month arrows
        x,y = 40, 63
        tagThisButton = "leftmonth"
        tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
        self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
        x,y = 150, 63
        tagThisButton = "rightmonth"
        tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
        self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
        #Print days
        self.canvas.create_text(100,90, text=strdays, font=fnta)
        self.canvas.pack (expand =1, fill =BOTH)
        self.canvas.tag_bind ("Arrow", "<ButtonRelease-1>", self.fnClick)
        self.canvas.tag_bind ("Arrow", "<Enter>", self.fnOnMouseOver)
        self.canvas.tag_bind ("Arrow", "<Leave>", self.fnOnMouseOut)
        self.fnFillCalendar()

    def fnCreateRightArrow(self, canv, x, y, strtagname):
        canv.create_polygon(x,y, [[x+0,y-5], [x+10, y-5] , [x+10,y-10] ,
            [x+20,y+0], [x+10,y+10] , [x+10,y+5] , [x+0,y+5]],
            tags = strtagname , fill="black", width=0)

    def fnCreateLeftArrow(self, canv, x, y, strtagname):
        canv.create_polygon(x,y, [[x+10,y-10], [x+10, y-5] , [x+20,y-5] ,
            [x+20,y+5], [x+10,y+5] , [x+10,y+10] ],
            tags = strtagname , fill="black", width=0)


    def fnClick(self,event):
        owntags =self.canvas.gettags(CURRENT)
        if "rightyear" in owntags:
            intyear = int(self.year_var.get())
            intyear +=1
            stryear = str(intyear)
            self.year_var.set(stryear)
        if "leftyear" in owntags:
            intyear = int(self.year_var.get())
            intyear -=1
            stryear = str(intyear)
            self.year_var.set(stryear)
        if "rightmonth" in owntags:
            if self.intmonth < 12 :
                self.intmonth += 1
                strnummonth = str(self.intmonth)
                strmonth = dictmonths[strnummonth]
                self.month_var.set(strmonth)
            else :
                self.intmonth = 1
                strnummonth = str(self.intmonth)
                strmonth = dictmonths[strnummonth]
                self.month_var.set(strmonth)
                intyear = int(self.year_var.get())
                intyear +=1
                stryear = str(intyear)
                self.year_var.set(stryear)
        if "leftmonth" in owntags:
            if self.intmonth > 1 :
                self.intmonth -= 1
                strnummonth = str(self.intmonth)
                strmonth = dictmonths[strnummonth]
                self.month_var.set(strmonth)
            else :
                self.intmonth = 12
                strnummonth = str(self.intmonth)
                strmonth = dictmonths[strnummonth]
                self.month_var.set(strmonth)
                intyear = int(self.year_var.get())
                intyear -=1
                stryear = str(intyear)
                self.year_var.set(stryear)
        self.fnFillCalendar()

    def fnFillCalendar(self):
        init_x_pos = 20
        arr_y_pos = [110,130,150,170,190,210]
        intposarr = 0
        self.canvas.delete("DayButton")
        self.canvas.update()
        intyear = int(self.year_var.get())
        monthcal = calendar.monthcalendar(intyear, self.intmonth)
        for row in monthcal:
            xpos = init_x_pos
            ypos = arr_y_pos[intposarr]
            for item in row:
                stritem = str(item)
                if stritem == "0":
                    xpos += 27
                else :
                    tagNumber = tuple((self.tagBaseNumber,stritem))
                    self.canvas.create_text(xpos, ypos , text=stritem,
                    font=fnta,tags=tagNumber)
                    xpos += 27
        intposarr += 1
        self.canvas.tag_bind ("DayButton", "<ButtonRelease-1>", self.fnClickNumber)
        self.canvas.tag_bind ("DayButton", "<Enter>", self.fnOnMouseOver)
        self.canvas.tag_bind ("DayButton", "<Leave>", self.fnOnMouseOut)

    def fnClickNumber(self,event):
        owntags = self.canvas.gettags(CURRENT)
        for x in owntags:
            if (x == "current") or (x == "DayButton"): pass
            else :
                strdate = (str(self.year_var.get()) + "/" +
                    str(self.intmonth) + "/" +
                    str(x))
                self.update_var.set(strdate)
                self.top.withdraw()

    def fnOnMouseOver(self,event):
        self.canvas.move(CURRENT, 1, 1)
        self.canvas.update()

    def fnOnMouseOut(self,event):
        self.canvas.move(CURRENT, -1, -1)
        self.canvas.update()

#----------------------------------------------------------------------

if __name__ == "__main__":
    root = Tk()
    aplicacion = Planificador(root)
    root.mainloop()
于 2013-11-04T20:14:36.183 に答える