当前位置: 首页>>代码示例>>Python>>正文


Python Solver.enable方法代码示例

本文整理汇总了Python中solver.Solver.enable方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.enable方法的具体用法?Python Solver.enable怎么用?Python Solver.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solver.Solver的用法示例。


在下文中一共展示了Solver.enable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Kakuro

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import enable [as 别名]
class Kakuro(Frame):

  def __init__(self, master):
    Frame.__init__(self, master)
    self.pack(expand = YES, fill = BOTH)
    self.timer = StopWatch(self)
    self.solver = Solver(self, self.timer)
    self.player = Player(self)
    self.timer.grid(row = 0, column = 0, sticky = 'ew')
    self.player.grid(row = 1, column = 0, sticky = 'news')
    self.player.grid_remove()
    self.solver.grid(row = 1, column = 0, sticky = 'news')
    self.rowconfigure(0, weight = 0)
    self.rowconfigure(1, weight = 1)
    self.columnconfigure(0, weight = 1)
    self.fileSaveDir = '.'        # directory for saving puzzles
    self.fileOpenDir = '.'        # directory for saved puzzles
    self.menu = self.makeMenu()
    self.solver.menu = self.menu
    self.enableSolver()

  def makeMenu(self):
    def notdone():
      showerror('Not implemented', 'Not yet available')

    win = self.winfo_toplevel()
    top = Menu(win)
    win.config(menu=top)

    file = top.file = Menu(top, tearoff = 0)
    file.add_command(label='New', command=self.dimensionDialog, underline=0)
    file.add_command(label='Open', command = self.openFile, underline = 0)
    file.add_command(label='Save', command=self.savePuzzleKro, underline=0)
    file.add_command(label='Clear',command = self.clearSolution, underline=0)
    file.add_command(label='Print', command=self.solver.printBoard, underline=0)
    file.add_command(label='Exit', command=self.wrapup, underline=1)
    file.entryconfigure('Save', state = DISABLED)

    puzzle = top.puzzle = Menu(top, tearoff = 0)
    puzzle.add_command(label='Open',command = self.loadPuzzle,underline = 0)
    puzzle.add_command(label='Save',command=self.savePuzzleKak,underline=0)
    puzzle.add_command(label='Clear',command = notdone, underline=0)
    puzzle.entryconfigure('Save', state = DISABLED)
    puzzle.entryconfigure('Clear', state = DISABLED)

    top.add_cascade(label='File', menu=file, underline=0)
    top.add_cascade(label='Puzzle', menu=puzzle, underline=0)
    return top

  def dimensionDialog(self):
    win = self.winDim = Toplevel()
    win.withdraw()  # Remain invisible while we figure out the geometry

    self.rowVar = StringVar()
    self.colVar = StringVar()
    rowFrame = LabelFrame(win, text = "Rows")
    colFrame = LabelFrame(win, text = "Columns")
    rowEntry = Scale(rowFrame, variable=self.rowVar, orient = VERTICAL,
                     from_ = 4, to = 40)
    colEntry = Scale(colFrame, variable = self.colVar, orient = VERTICAL,
                     from_ = 4, to = 40)
    rowEntry.set(self.solver.rows-1)
    colEntry.set(self.solver.cols-1)
    rowEntry.pack()
    colEntry.pack()

    ok = Button(win, text = 'Okay', command = self.okayDim)
    cancel = Button(win, text = 'Cancel', command = win.destroy)
    ok.grid(row = 1, column = 0)
    rowFrame.grid(row = 0, column = 0)
    colFrame.grid(row = 0, column = 1)
    cancel.grid(row = 1, column = 1)

    displayDialog(win, self.winfo_toplevel(), 'Dimension', True)

  def okayDim(self):
    self.winDim.destroy()
    rows = int(self.rowVar.get())
    cols = int(self.colVar.get())
    self.drawNew(rows, cols, 'Solver')
    self.timer.pause(reset=True)

  def drawNew(self, rows, cols, mode):
    self.menu.file.entryconfigure('Save', state = DISABLED)
    if mode == 'Solver':
      self.solver.drawNew(rows, cols)
      self.enableSolver()
    else:
      self.player.drawNew(rows, cols)
      self.enablePlayer()

  def openFile(self):
    # Mainly for development, to avoid having to enter puzzles
    # over and over
    fname = askopenfile( filetypes = [('Kakuro Files', '.kro')],
                         title = 'Open Puzzle File',
                         defaultextension = 'kro',
                        initialdir = self.fileOpenDir)
    if not fname:
        return
#.........这里部分代码省略.........
开发者ID:saulspatz,项目名称:Kakuro,代码行数:103,代码来源:kakuro.py


注:本文中的solver.Solver.enable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。