def setup(self):
        for child in self.tk.winfo_children():
            child.destroy()
        n = True
        for i in range(len(self.board)):
            for j in range(len(self.board[i])):

                if (self.board[i][j] == -100):
                    if (self.turn == len(clicked) - 1):
                        if n:
                            tile = Frame(self.tk,
                                         width=60,
                                         height=60,
                                         bg="#E74C3C",
                                         borderwidth=0)
                        else:
                            tile = Frame(self.tk,
                                         width=60,
                                         height=60,
                                         bg="#C0392B",
                                         borderwidth=0)
                    else:
                        if n:
                            tile = Frame(self.tk,
                                         width=60,
                                         height=60,
                                         bg="#34495E",
                                         borderwidth=0)
                        else:
                            tile = Frame(self.tk,
                                         width=60,
                                         height=60,
                                         bg="#2C3E50",
                                         borderwidth=0)
                else:
                    if n:
                        tile = Frame(self.tk,
                                     width=60,
                                     height=60,
                                     bg="#ECF0F1",
                                     borderwidth=0)
                    else:
                        tile = Frame(self.tk,
                                     width=60,
                                     height=60,
                                     bg="#DFE4E6",
                                     borderwidth=0)

                    if (self.board[i][j] == 1):
                        Label(tile,
                              text=self.board[i][j],
                              bg=tile.cget("bg"),
                              font=("CourierNew 24 bold"),
                              foreground="#3498DB").place(x=30,
                                                          y=30,
                                                          anchor="center")
                    elif (self.board[i][j] == 2):
                        Label(tile,
                              text=self.board[i][j],
                              bg=tile.cget("bg"),
                              font=("CourierNew 24 bold"),
                              foreground="#2ECC71").place(x=30,
                                                          y=30,
                                                          anchor="center")
                    elif (self.board[i][j] == 3):
                        Label(tile,
                              text=self.board[i][j],
                              bg=tile.cget("bg"),
                              font=("CourierNew 24 bold"),
                              foreground="#E67E22").place(x=30,
                                                          y=30,
                                                          anchor="center")
                    elif (self.board[i][j] == 4):
                        Label(tile,
                              text=self.board[i][j],
                              bg=tile.cget("bg"),
                              font=("CourierNew 24 bold"),
                              foreground="#9B59B6").place(x=30,
                                                          y=30,
                                                          anchor="center")
                    # elif (self.board[i][j] == 5):
                    # Label(tile, text=self.board[i][j], bg = tile.cget("bg"), font=("CourierNew 24 bold"), foreground="#E74C3C").place(x = 30, y = 30, anchor="center")
                    # elif (self.board[i][j] == 6):
                    # Label(tile, text=self.board[i][j], bg = tile.cget("bg"), font=("CourierNew 24 bold"), foreground="#1ABC9C").place(x = 30, y = 30, anchor="center")
                    # elif (self.board[i][j] == 7):
                    # Label(tile, text=self.board[i][j], bg = tile.cget("bg"), font=("CourierNew 24 bold"), foreground="#2C3E50").place(x = 30, y = 30, anchor="center")
                    # elif (self.board[i][j] == 8):
                    # Label(tile, text=self.board[i][j], bg = tile.cget("bg"), font=("CourierNew 24 bold"), foreground="#7F8C8D").place(x = 30, y = 30, anchor="center")

                tile.grid(row=i, column=j)
                n = not n
            n = not n
        tile = Frame(self.tk,
                     width=60 * (j + 1),
                     height=60,
                     bg="#95A5A6",
                     borderwidth=0)
        tile.grid(row=i + 1, column=0, columnspan=j + 1)
        Button(tile,
               text="◀",
               bg="#2ECC71",
               borderwidth=0,
               font=("CourierNew 24 bold"),
               foreground="#ECF0F1",
               command=self.prev).pack(side=LEFT,
                                       expand=False,
                                       fill='both',
                                       anchor="w")
        Button(tile,
               text="▶",
               bg="#2ECC71",
               borderwidth=0,
               font=("CourierNew 24 bold"),
               foreground="#ECF0F1",
               command=self.next).pack(side=RIGHT,
                                       expand=False,
                                       fill='both',
                                       anchor="e")
        b = Frame(tile,
                  width=60 * (j - 0.4),
                  height=60,
                  bg="#3498DB",
                  borderwidth=0)
        Label(b,
              text="Move: " + str(self.move),
              bg="#3498DB",
              font=("CourierNew 18 bold"),
              foreground="#ECF0F1").place(x=(60 * (j - 0.4)) / 2,
                                          y=30,
                                          anchor="center")
        b.pack(expand=True, fill='both', side="left")
Example #2
0
        block_size = int(main_window.winfo_screenheight() / 4)
        main_window.geometry(str(block_size * 6) + 'x' + str(block_size * 4))
        main_window.overrideredirect(True)

    # 16个时间显示正方形
    bc = Create_blocks(main_window, block_size)

    # 开启二进制钟
    CLOCK_STATUS = True

    # 信息和按键展示框
    info_frame = Frame(main_window,
                       height=block_size * 4,
                       width=block_size * 2)
    info_frame.place(x=block_size * 5, y=block_size * 2, anchor='center')
    original_bg = info_frame.cget('bg')

    # 博文推送信息框和番茄钟信息框
    blogging_status = StringVar()
    blogger_label = Label(info_frame, textvariable=blogging_status)
    blogger_label.place(x=block_size, y=block_size * 0.5, anchor='center')
    pomodoro_info = StringVar()
    status_label = Label(info_frame,
                         textvariable=pomodoro_info,
                         font=('Helvetica', 24))
    status_label.place(x=block_size, y=block_size, anchor='center')

    # 设置
    def setting_time():
        setting_wd = Toplevel()
        setting_wd.title('番茄钟设置')
Example #3
0
class StreamFrame:
    def __init__(self, stream: Stream, parent, scrollWindow, searchFrame,
                 color):
        self.frame = Frame(scrollWindow,
                           relief=GROOVE,
                           highlightbackground=color,
                           highlightcolor=color,
                           highlightthickness=3)
        self.stream = stream
        self.parent = parent
        self.searchFrame = searchFrame

        self.previewFrame = Frame(self.frame, width=322, height=182)
        self.previewFrame.grid_propagate(False)
        self.boxFrame = Frame(self.frame)
        self.boxArtFrame = Frame(self.boxFrame)
        self.boxArtLabelFrame = Frame(self.boxFrame)
        self.filterFrame = Frame(self.frame)

        self.labelImage = None
        self.labelBoxArt = None
        self.buttonFilterGame = None
        self.buttonFilterStreamer = None
        self.buttonFilterCombined = None

        self.previewTitle = StringVar()
        self.previewImage = None
        self.boxArtImage = None
        self.previewName = StringVar()
        self.previewViewers = StringVar()

        self.setStringVars()
        self.addPreview()
        self.addFilterFrame()
        self.gridFrames()

    def gridFrames(self):
        self.previewFrame.grid(row=0, sticky=NSEW)
        self.boxFrame.grid(row=1, sticky=NSEW)
        self.boxArtFrame.grid(row=0, column=0, sticky=NSEW)
        self.boxArtLabelFrame.grid(row=0, column=1, sticky=W)
        self.filterFrame.grid(row=2, sticky=NSEW)

    def setStream(self, stream):
        self.stream = stream
        self.setStringVars()

    def setStringVars(self):
        self.previewTitle.set(
            self.stream.streamTitle.encode("ascii", "ignore").decode())
        self.boxArtImage = self.stream.DEFAULT_BOX_ART
        self.previewImage = self.stream.DEFAULT_STREAM_PREVIEW
        self.previewName.set(self.stream.stylizedStreamName)
        self.previewViewers.set(self.stream.viewerCount +
                                LabelConstants.VIEWERS)

    def addPreview(self):
        self.labelImage = Label(self.previewFrame,
                                image=self.previewImage,
                                bd=1)
        self.labelImage.bind(MiscConstants.BIND_LEFT_MOUSE,
                             lambda x: self.onClick(None))
        self.labelImage.grid(row=1, sticky=W)
        dummyImageToMakeLabelHaveWidthInPixels = PhotoImage(width=1, height=1)
        dummyLabelToGetWidthOfText = Label(None,
                                           textvariable=self.previewTitle)
        titleWidth = min(dummyLabelToGetWidthOfText.winfo_reqwidth() - 4, 308)
        labelTitle = Label(self.previewFrame,
                           image=dummyImageToMakeLabelHaveWidthInPixels,
                           textvariable=self.previewTitle,
                           fg="white",
                           bg="black",
                           compound=RIGHT,
                           anchor=W,
                           width=titleWidth)
        labelTitle.bind(MiscConstants.BIND_LEFT_MOUSE,
                        lambda x: self.onClick(None))
        labelTitle.grid(row=1, sticky=NW, padx=4, pady=4)
        self.labelBoxArt = Label(self.previewFrame,
                                 image=self.boxArtImage,
                                 bd=1)
        self.labelBoxArt.bind(MiscConstants.BIND_LEFT_MOUSE,
                              lambda x: self.onClick(None))
        self.labelBoxArt.grid(row=1, column=0, sticky=SW, padx=4, pady=4)
        labelName = Label(self.previewFrame,
                          textvariable=self.previewName,
                          fg="white",
                          bg="#b71ef7")
        labelName.bind(MiscConstants.BIND_LEFT_MOUSE,
                       lambda x: self.onClick(None))
        labelName.grid(row=1, sticky=S, padx=4, pady=4)
        labelViewers = Label(self.previewFrame,
                             textvariable=self.previewViewers,
                             fg="white",
                             bg="black")
        labelViewers.bind(MiscConstants.BIND_LEFT_MOUSE,
                          lambda x: self.onClick(None))
        labelViewers.grid(row=1, sticky=SE, padx=4, pady=4)

    def addFilterFrame(self):
        labelFilter = Label(self.filterFrame,
                            text=LabelConstants.FILTER,
                            anchor=W)
        labelFilter.grid(row=0, column=0, sticky=NSEW, padx=(4, 2))
        self.buttonFilterStreamer = Button(
            self.filterFrame,
            text=LabelConstants.FILTER_STREAMER,
            width=10,
            command=lambda: self.parent.addFilter(
                self.stream.stylizedStreamName, None))
        self.buttonFilterStreamer.grid(row=0,
                                       column=1,
                                       sticky=NSEW,
                                       padx=(2, 4),
                                       pady=(0, 4))
        self.buttonFilterGame = Button(
            self.filterFrame,
            text=LabelConstants.FILTER_GAME,
            width=10,
            command=lambda: self.parent.addFilter(None, self.stream.gameTitle))
        self.buttonFilterGame.grid(row=0,
                                   column=2,
                                   sticky=NSEW,
                                   padx=4,
                                   pady=(0, 4))
        self.buttonFilterCombined = Button(
            self.filterFrame,
            text=LabelConstants.FILTER_COMBO,
            width=13,
            command=lambda: self.parent.addFilter(
                self.stream.stylizedStreamName, self.stream.gameTitle))
        self.buttonFilterCombined.grid(row=0,
                                       column=3,
                                       sticky=NSEW,
                                       padx=(4, 0),
                                       pady=(0, 4))

    def onClick(self, event):
        if self.frame.cget("highlightbackground") == "red":
            self.frame.config(highlightbackground="grey",
                              highlightcolor="grey")
            idx = self.searchFrame.selectedStreamsListbox.get(0, END).index(
                self.stream.streamName)
            self.searchFrame.selectedStreamsListbox.delete(idx)
        else:
            self.frame.config(highlightbackground="red", highlightcolor="red")
            self.searchFrame.selectedStreamsListbox.insert(
                END, self.stream.streamName)
Example #4
0
class Tooltip2:
    def __init__(self,
                 widget,
                 *,
                 bg='#FFFFEA',
                 pad=(5, 3, 5, 3),
                 text='widget info',
                 waittime=400,
                 wraplength=500,
                 pos=TIP_RIGHT):

        self.waittime = waittime  # in miliseconds, originally 500
        self.wraplength = wraplength  # in pixels, originally 180
        self.widget = widget
        self.text = text

        self.widget.bind('<Configure>', self.onConfigure, add='+')
        # self.widget.winfo_toplevel().bind('<Configure>', self.onWindowConfigure, add='+')

        self.bg = bg
        self.pad = pad
        self.pos = pos
        self.id = None
        self.win = None
        self.label = None

    def onWindowConfigure(self, event):
        if not event.widget.winfo_viewable():
            self.hide()
        else:
            self.updatePosition()

    def onConfigure(self, event=None):
        self.updatePosition()

    def onEnter(self, event=None):
        self.schedule()

    def onLeave(self, event=None):
        self.unschedule()
        self.hide()

    def schedule(self):
        self.unschedule()
        self.id = self.widget.after(self.waittime, self.show)

    def unschedule(self):
        id_ = self.id
        self.id = None
        if id_:
            self.widget.after_cancel(id_)

    def show(self, text=None, pos=None):
        self.hide()

        if text is not None:
            self.text = text
        if pos is not None:
            self.pos = pos

        bg = self.bg
        pad = self.pad
        widget = self.widget

        # self.widget.bind('<Configure>', self.onConfigure, add='+')

        self.win = Frame(self.widget.winfo_toplevel(),
                         background=bg,
                         highlightcolor='red',
                         highlightthickness=2,
                         highlightbackground='red',
                         borderwidth=0)

        self.label = Label(
            self.win,
            text=self.text,
            justify=LEFT,
            background=bg,
            # foreground='blue',
            # relief=SOLID,
            borderwidth=0,
            wraplength=self.wraplength)

        self.label.grid(padx=(pad[0], pad[2]),
                        pady=(pad[1], pad[3]),
                        sticky=NSEW)
        # self.win.grid()

        # self.win.place(in_=self.widget, x=0,y=0)
        # widget.update_idletasks()

        self.updatePosition()

    def hide(self):
        if self.win:
            # self.widget.unbind('<Configure>', self.onConfigure)
            self.win.destroy()
            self.win = None

    def updatePosition(self):
        if self.win:
            x, y = self._tip_pos_calculator(self.widget, self.win)
            self.win.place(in_=self.widget, x=x, y=y)

    def _tip_pos_calculator(self, widget, frm, tip_delta=(5, 3)):

        w = widget

        width, height = frm.winfo_width(), frm.winfo_height()

        width = self.label.winfo_reqwidth() + self.pad[0] + self.pad[
            2] + float(self.win.cget('highlightthickness')) * 2
        height = self.label.winfo_reqheight() + self.pad[1] + self.pad[
            3] + float(self.win.cget('highlightthickness')) * 2

        if self.pos == TIP_BELOW:
            x1, y1 = 0, w.winfo_height() + tip_delta[1]
        elif self.pos == TIP_ABOVE:
            x1, y1 = 0, -height - tip_delta[1]
        else:
            x1, y1 = w.winfo_width() + tip_delta[0], (w.winfo_height() -
                                                      height) / 2

        return x1, y1
Example #5
0
class ButtonGroup(WidgetMixin, ScheduleMixin, DestroyMixin, FocusMixin,
                  DisplayMixin, ReprMixin):
    def __init__(self,
                 master,
                 options,
                 selected,
                 horizontal=False,
                 command=None,
                 grid=None,
                 align=None,
                 args=None):

        self._master = master
        self._grid = grid
        self._align = align
        self._visible = True

        # Set (using StringVar set() method) the selected option **number**
        self.tk = Frame(master.tk)
        self._selected = StringVar(master=self.tk.winfo_toplevel())
        self._selected.set(selected)

        self.description = "[ButtonGroup] object with selected option \"" + self._selected.get(
        ) + "\""
        self._options = []  # List of RadioButton objects
        self._layout_manager = "grid"

        # Create a Tk frame object to contain the RadioButton objects

        # Position the radio buttons in the Frame
        gridx = 0
        gridy = 0

        # Loop through the list given, creating a RadioButton object from each
        # Defaults to setting the hidden value to the same as the text

        for button in options:
            # If only a 1D list was provided, auto number the items FROM 1
            if not isinstance(button, list):
                button = [button, options.index(button) + 1]

            # Create a radio button object
            rbutton = RadioButton(self,
                                  text=str(button[0]),
                                  value=str(button[1]),
                                  variable=self._selected)

            # Add this radio button to the internal list
            self._options.append(rbutton)

            # Place on grid
            utils.auto_pack(rbutton, self, [gridx, gridy], "left")

            # Which way the buttons go
            if horizontal:
                gridx += 1
            else:
                gridy += 1

            # Set the callback
            rbutton.tk.config(command=self._command_callback)

        # Add a command if there was one
        self.update_command(command, args)

        # Pack the whole button group
        utils.auto_pack(self, master, grid, align)

    # PROPERTIES
    # -----------------------------------

    @property
    def bg(self):
        return (self.tk.cget("bg"))

    @bg.setter
    def bg(self, color):
        self.tk.config(bg=color)
        for item in self._options:
            item.bg = color

    # Gets the selected value (1, 2, 3 etc.)
    @property
    def value(self):
        return (self._selected.get())

    # Sets which option is selected (if it doesn't exist, nothing is selected)
    @value.setter
    def value(self, value):
        self._selected.set(str(value))

    # Gets the text of the currently selected option
    @property
    def value_text(self):
        search = self._selected.get(
        )  # a string containing the selected option
        # This is a bit nasty - suggestions welcome
        for item in self._options:
            if item.value == search:
                return item.text
        return ""

    # Wondering if this is really confusing. value_text is the text associated with the selected
    # option. You can change it because it's useful to be able to *get* it, but maybe this is weird.
    @value_text.setter
    def value_text(self, value):
        search = self._selected.get()  # Currently selected number
        for item in self._options:
            if item.value == search:
                item.text = str(value)
                print(item.text)
                return 0
        utils.error_format("Could not set value text - no matching option")

    # Get the text colour as a string
    @property
    def text_color(self):
        return self._options[0].text_color

    # Set the text colour
    @text_color.setter
    def text_color(self, color):
        for item in self._options:
            item.text_color = color

    # Get the current font as a string
    @property
    def font(self):
        return self._options[0].font

    # Set the current font
    @font.setter
    def font(self, font):
        for item in self._options:
            item.font = font

    # Get the current text size as an integer
    @property
    def text_size(self):
        return self._options[0].text_size

    # Set the font size
    @text_size.setter
    def text_size(self, size):
        for item in self._options:
            item.text_size = size

    # METHODS
    # -----------------------------------

    # To help with debugging - return list of text/value pairs
    def get_group_as_list(self):
        return [[option.text, option.value] for option in self._options]

    def update_command(self, command, args=None):
        if command is None:
            self._command = lambda: None
        else:
            if args is None:
                self._command = command
            else:
                self._command = utils.with_args(command, *args)

    def _command_callback(self):
        self._command()

    # DEPRECATED METHODS
    # -----------------------------------
    # Get selected value (e.g. 1, 2, 3)
    def get(self):
        return self._selected.get()
        utils.deprecated(
            "ButtonGroup get() is deprecated. Please use the value property instead."
        )

    # Set which option is selected
    def set(self, value):
        self._selected.set(str(value))
        utils.deprecated(
            "ButtonGroup set() is deprecated. Please use the value property instead."
        )