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


Python Tk.call方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import call [as 别名]
 def __init__(self, size, units, unitmult=1, *,
 down, line=1, textbottom=False):
     root = Tk()
     scaling = root.call("tk", "scaling") * 72  # pixels/in
     scaling *= unitmult / {"mm": 25.4, "in": 1}[units]
     self.flip = down
     if self.flip < 0:
         self.scaling = (+scaling, -scaling)
     else:
         self.scaling = (+scaling, +scaling)
     self.linewidth = line * scaling
     self.canvas = tkinter.Canvas(root,
         relief=tkinter.SUNKEN, borderwidth=1,
         background="white",
         height=size[1] * scaling, width=size[0] * scaling,
     )
     self.canvas.pack(fill=tkinter.BOTH, expand=True)
     self.fonts = dict()
开发者ID:diyjack,项目名称:python-altium,代码行数:20,代码来源:tk.py

示例2: Controller

# 需要导入模块: from tkinter import Tk [as 别名]
# 或者: from tkinter.Tk import call [as 别名]
class Controller():
    def __init__(self):
        if not DISABLE_DISPLAY:
            self.__root = Tk()
            self.__windowsystem = self.__root.call('tk', 'windowingsystem')
            self.__root.bind_all('<Key>', self.key)
        self.__running = True
        self.__score = -1
        self.__autoplay = DEFAULT_AUTOPLAY
        self.__gen_random()
        self.__model = Model(self)
        self.__gamestate_api = GameState(self.__model)
        if not DISABLE_DISPLAY:
            self.__view = View(self.__root, self)
        self.__blockfield = self.__model.blockfield
        self.__lost = False
        self.__model.start()
        self.__model.enable_autoplay(self.__autoplay)

    # Generate a list of random blocks.  We do this here, at startup, so any use
    # you make of random numbers does not change the sequence of
    # blocks.
    def __gen_random(self):
        self.__rand = Random()
        #self.__rand.seed(42)
        self.rand_ix = 0
        self.maxrand = 100000
        maxblocktype = 6 # there are 7 different block types, indexed 0 to 6
        self.randlist = []
        for _i in range(self.maxrand):
            self.randlist.append(self.__rand.randint(0, maxblocktype))

    def get_random_blocknum(self):
        self.rand_ix = (self.rand_ix + 1) % self.maxrand
        return self.randlist[self.rand_ix]

    def register_block(self, block):
        if not DISABLE_DISPLAY:
            self.__view.register_block(block)

    def unregister_block(self, block):
        if not DISABLE_DISPLAY:
            self.__view.unregister_block(block)

    def update_blockfield(self, blockfield):
        # we keep a reference to the blockfield in case we need to add
        # any views later
        self.__blockfield = blockfield
        if not DISABLE_DISPLAY:
            self.__view.update_blockfield(blockfield)

    #some helper functions to hide the controller implementation from
    #the model and the controller
    def update_score(self, score):
        self.__score = score

    @property
    def score(self):
        return self.__score

    def game_over(self):
        self.__lost = True
        if DISABLE_DISPLAY:
            print("Score: ", self.__score)
            self.__running = False
        else:
            self.__view.game_over()

    def key(self, event):
        if event.char == ' ':
            self.__model.drop_block()
        elif event.char == 'q':
            self.__running = False
        elif event.char == 'a':
            self.__model.move(Direction.LEFT)
        elif event.char == 's':
            self.__model.move(Direction.RIGHT)
        elif event.char == 'k':
            self.__model.rotate(Direction.LEFT)
        elif event.char == 'l':
            self.__model.rotate(Direction.RIGHT)
        elif event.char == 'y':
            self.__autoplay = not self.__autoplay
            self.__model.enable_autoplay(self.__autoplay)
            if not DISABLE_DISPLAY:
                self.__view.show_autoplay(self.__autoplay)
        elif event.char == 'r':
            if not DISABLE_DISPLAY:
                self.__view.clear_messages()
            self.__lost = False
            self.__model.restart()
            self.__model.enable_autoplay(self.__autoplay)

    def run(self, autoplayer):
        dropped = False
        while self.__running:
            if not self.__lost:
                if dropped and self.__autoplay:
                    self.__model.reset_counts()
                    autoplayer.next_move(self.__gamestate_api)
#.........这里部分代码省略.........
开发者ID:magetron,项目名称:ENGF0002,代码行数:103,代码来源:te_controller.py


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