Esempio n. 1
0
def network_name(n, old_root):
    try:
        old_root.destroy()
        r = Tk()
        r.iconbitmap(r"D:\Graphicloads-Medical-Health-Dna.ico")
        r.geometry('320x200')
        canvas = Canvas(r)
        frame = Frame(canvas)
        scroll = Scrollbar(r, orient='vertical', command=canvas.yview)

        for i in range(int(n)):
            labl = Label(frame,
                         text="Network Name: {}".format(i + 1),
                         width=45)
            labl.pack()
            e = Entry(frame)
            l.append(e)
            e.pack()

        b = Button(frame, text="OK", command=lambda: multiple_entry(l, r, n))
        b.pack()

        canvas.configure(yscrollcommand=scroll.set)
        scroll.pack(side="right", fill="y")
        canvas.pack(fill="both", expand=True)
        canvas.create_window((4, 4), window=frame, anchor="nw")
        frame.bind('<Configure>',
                   lambda event, canvas=canvas: onFrameConfigure(canvas))
        r.resizable(0, 0)
        r.mainloop()
    except:
        r.destroy()
        network_no()
Esempio n. 2
0
    def _init_mainframe(self, parent):
        def onFrameConfigure(canvas):
            '''Reset the scroll region to encompass the inner frame'''
            canvas.configure(scrollregion=canvas.bbox("all"))

        def FrameWidth(event, canvas, canvas_window):
            canvas_width = event.width
            canvas.itemconfig(canvas_window, width=canvas_width)

        canvas = Canvas(parent, relief="sunken", background="gray90")
        frame = Frame(canvas, background="#ffffff")
        scrollbar = Scrollbar(parent, orient="vertical", command=canvas.yview)
        canvas.configure(yscrollcommand=scrollbar.set)

        scrollbar.pack(side="right", fill="y")
        canvas.pack(side="left", fill="both", expand=True)
        canvas_window = canvas.create_window(0,
                                             0,
                                             width=canvas.winfo_x(),
                                             window=frame,
                                             anchor="nw")

        frame.bind("<Configure>",
                   lambda event, canvas=canvas: onFrameConfigure(canvas))
        canvas.bind('<Configure>',
                    lambda event, canvas=canvas, canvas_window=canvas_window:
                    FrameWidth(event, canvas, canvas_window))

        for game in self.games_config["GAMES"]:
            allies, enemies, times = self.games_config["GAMES"][game].split(
                "|")
            allies = allies.split(", ")
            enemies = enemies.split(", ")
            times = times.split(", ")
            self.add_gamecard(frame, allies, enemies, times)
Esempio n. 3
0
class ScrolledFrame(Frame):
    def __init__(self, master, **kw):
        self.frame = Frame(master)
        self.canvas = Canvas(self.frame, bd=0, highlightthickness=0)
        yscrollbar = AutoScrollbar(self.frame, command=self.canvas.yview)
        Frame.__init__(self, self.canvas, **kw)

        self.canvas.config(yscrollcommand=yscrollbar.set)
        self.id = self.canvas.create_window(0, 0, window=self, anchor="nw")
        self.frame.columnconfigure(0, weight=1)
        self.frame.rowconfigure(0, weight=1)

        self.canvas.grid(column=0, row=0, sticky="NSEW")
        yscrollbar.grid(column=1, row=0, rowspan=2, sticky="NSEW")

        self.frame.bind("<Configure>", self.canvas_config)
        self.bind_all("<MouseWheel>", self.on_mousewheel)
        self.bind_all("<KeyPress-Up>",
                      lambda e: self.canvas.yview_scroll(-1, "units"))
        self.bind_all("<KeyPress-Down>",
                      lambda e: self.canvas.yview_scroll(1, "units"))

    def canvas_config(self, event):
        frameWidth = self.frame.winfo_width()
        canvas = self.canvas
        canvas.itemconfig(self.id, width=frameWidth)
        canvas.configure(scrollregion=canvas.bbox(self.id), width=frameWidth)

    def on_mousewheel(self, event):
        direction = -1 if event.delta > 0 else 1
        self.canvas.yview_scroll(direction, "units")

    def grid(self, **kw):
        self.frame.grid(**kw)
Esempio n. 4
0
    def __init__(self, editor):

        editor.title('My Text Editor')
        title_bar = Frame(editor, bg='pink')
        title_bar.bind()
        editor.geometry('1000x500')
        font_type_size = ('Franklin Gothic', 8)

        self.editor = editor
        self.filename = None
        self.textarea = tk.Text(editor, {
            'bg': 'RosyBrown1',
            'font': font_type_size
        })
        self.scroll = tk.Scrollbar(editor, {'bg': 'salmon'},
                                   command=self.textarea.yview)
        self.textarea.configure(yscrollcommand=self.scroll.set)
        self.textarea.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        self.scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.userinput = tk.StringVar()
        self.menubar = Menu(self)
        self.statusbar = Status(self)
        self.output = tk.Text(editor, {
            'bg': 'RosyBrown1',
            'font': font_type_size
        },
                              wrap='word')
        self.shortcut_keys()
Esempio n. 5
0
def main():
    root = Tk()
    root.title("Rx for Python rocks")
    scheduler = TkinterScheduler(root)

    mousemove = Subject()

    frame = Frame(root, width=600, height=600)

    def move(event):
        mousemove.on_next(event)
    frame.bind("<Motion>", move)

    text = 'TIME FLIES LIKE AN ARROW'
    labels = [Label(frame, text=c) for c in text]

    def handle_label(i, label):
        label.config(dict(borderwidth=0, padx=0, pady=0))

        def on_next(ev):
            label.place(x=ev.x + i*12 + 15, y=ev.y)
        mousemove.delay(i*100).subscribe_(on_next, scheduler=scheduler)

    for i, label in enumerate(labels):
        handle_label(i, label)

    frame.pack()
    root.mainloop()
    def right_frame(parent):
        rf_width = 300
        rf_height = 360
        # right side frame
        frame_right = LabelFrame(
            parent.building_pos_window,
            text="Building Position",
            width=rf_width - 10,
            height=rf_height - 10,
        )

        frame_right.grid_rowconfigure(0, weight=1)
        frame_right.grid_columnconfigure(0, weight=1)
        frame_right.grid_propagate(False)

        canvas_right = Canvas(frame_right)
        canvas_right.grid(row=0, column=0, sticky=N + W)

        # Link a scrollbar to the canvas
        def on_mousewheel(event):
            canvas_right.yview_scroll(int(-1 * (event.delta / 120)), "units")

        def bound_to_mousewheel(event):
            canvas_right.bind_all("<MouseWheel>", on_mousewheel)

        def unbound_to_mousewheel(event):
            canvas_right.unbind_all("<MouseWheel>")

        y_scrollbar = Scrollbar(frame_right,
                                orient="vertical",
                                command=canvas_right.yview)
        y_scrollbar.grid(row=0, column=1, sticky='ns')
        canvas_right.configure(yscrollcommand=y_scrollbar.set)

        inner_frame_right = Frame(canvas_right)
        inner_frame_right.bind('<Enter>', bound_to_mousewheel)
        inner_frame_right.bind('<Leave>', unbound_to_mousewheel)

        canvas_right.create_window((0, 0),
                                   window=inner_frame_right,
                                   anchor='nw')

        idx = 0
        for e_name in BuildingNames:
            building_name_xy_config_frame(
                inner_frame_right, idx, e_name.value,
                parent.bot_building_pos.get(e_name.value, [-1, -1])
                if parent.bot_building_pos is not None else [-1, -1])
            idx = idx + 1

        inner_frame_right.update_idletasks()

        frame_right.config(width=rf_width - 10, height=360 - 10)
        canvas_right.config(width=rf_width - 10,
                            height=360 - 10,
                            scrollregion=canvas_right.bbox("all"))

        frame_right.grid(row=0, column=1, padx=5, pady=5, sticky=N + W)

        return inner_frame_right
Esempio n. 7
0
class ScrollableFrame(Frame):

    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

        self.canvas = Canvas(self)
        self.inner_frame = Frame(self.canvas)
        self.vertical_scrollbar = Scrollbar(self, orient=VERTICAL, command=self.canvas.yview)
        self.horizontal_scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.canvas.xview)
        self.canvas.configure(yscrollcommand=self.vertical_scrollbar.set,
                              xscrollcommand=self.horizontal_scrollbar.set)

        self.canvas.grid(row=0, column=0, sticky='news')
        self.vertical_scrollbar.grid(row=0, column=1, sticky='ns')
        self.horizontal_scrollbar.grid(row=1, column=0, stick='we')

        self.canvas.create_window((4, 4), window=self.inner_frame, anchor='nw')
        self.inner_frame.bind("<Configure>", self._on_frame_configure)

    # noinspection PyUnusedLocal
    def _on_frame_configure(self, event):
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))
Esempio n. 8
0
def makeWindow():
    'create GUI'
    frame = Frame(width=100, height=100, background = "blue")
    frame.bind("<Button-1>", handler)
    frame.bind('<Button-3>', handler2)
    frame.pack()
    frame.mainloop()
Esempio n. 9
0
class Explorer(Toplevel):
    def __init__(self, folder):
        super().__init__(bg='white')
        self.f = folder
        self.title(self.f.name)
        self.selected = set()
        self.fr = Frame(self, bg='white')
        self.fr.pack(fill=BOTH, expand=True)
        for i, f in enumerate(folder.fileList):
            name = f.split('.')[0]
            format = f.split('.')[1]
            newFile = File(self.fr, name, format)
            k = int(i / 5)
            j = int(i % 5)
            newFile.grid(row=k, column=j, padx=15, columnspan=1)

        self.attributes('-topmost', 'true')

        self.fr.bind('<Button-1>', self.onClick)

    def onClick(self, event):
        for item in self.selected:
            if type(item).__name__ == 'Folder':
                icon = ImageTk.PhotoImage(Image.open('Images/folder.png'))
                item.img.configure(image=icon)
                item.img.image = icon
                item.lbl.configure(fg='#000')
            if type(item).__name__ == 'File':
                icon = ImageTk.PhotoImage(Image.open('Images/file.png'))
                item.img.configure(image=icon)
                item.img.image = icon
                item.lbl.configure(fg='#000')
Esempio n. 10
0
def main():
    global state_pub
    global root

    global max_velocity
    global max_steering_angle
    max_velocity = rospy.get_param("~speed", 2.0)
    max_steering_angle = rospy.get_param("~max_steering_angle", 0.34)

    state_pub = rospy.Publisher("mux/ackermann_cmd_mux/input/teleop",
                                AckermannDriveStamped,
                                queue_size=1)
    rospy.Timer(rospy.Duration(0.1), publish_cb)
    atexit.register(exit_func)
    os.system("xset r off")

    root = Tk()
    frame = Frame(root, width=100, height=100)
    frame.bind("<KeyPress>", keydown)
    frame.bind("<KeyRelease>", keyup)
    frame.pack()
    frame.focus_set()
    lab = Label(
        frame,
        height=10,
        width=30,
        text=
        "Focus on this window\nand use the WASD keys\nto drive the car.\n\nPress Q to quit",
    )
    lab.pack()
    print("Press %c to quit" % QUIT)
    root.mainloop()
Esempio n. 11
0
async def main(loop):
    mousemoves = Subject()

    root = Tk()
    root.title("asyncitertools")

    frame = Frame(root, width=800, height=600)
    frame.bind("<Motion>", lambda ev: asyncio.ensure_future(mousemoves.send(ev)))

    tasks = []
    for idx, char in enumerate("TIME FLIES LIKE AN ARROW"):
        label = Label(frame, text=char)
        label.config({'borderwidth': 0,
                      'padx': 0,
                      'pady': 0})

        tasks.append(asyncio.ensure_future(position_label(label, idx, mousemoves)))

    frame.pack()
    try:
        while True:
            root.update()
            await asyncio.sleep(0.0005)
    except TclError as e:
        if "application has been destroyed" not in e.args[0]:
            raise
    finally:
        for task in tasks:
            task.cancel()
Esempio n. 12
0
def main() -> None:
    root = Tk()
    root.title("Rx for Python rocks")
    scheduler = TkinterScheduler(root)

    mousemoves: Subject[Event[Any]] = Subject()

    frame = Frame(root, width=600, height=600)
    frame.bind("<Motion>", mousemoves.on_next)

    text = "TIME FLIES LIKE AN ARROW"

    def on_next(info: Tuple[tkinter.Label, "Event[Frame]", int]) -> None:
        label, ev, i = info
        label.place(x=ev.x + i * 12 + 15, y=ev.y)

    def label2stream(
            label: tkinter.Label, index: int
    ) -> Observable[Tuple[tkinter.Label, "Event[Frame]", int]]:

        return mousemoves.pipe(
            ops.map(lambda ev: (label, ev, index)),
            ops.delay(index * 0.1),
        )

    def char2label(char: str) -> Label:
        return Label(frame, text=char, borderwidth=0, padx=0, pady=0)

    reactivex.from_(text).pipe(
        ops.map(char2label),
        ops.flat_map_indexed(label2stream),
    ).subscribe(on_next, on_error=print, scheduler=scheduler)

    frame.pack()
    root.mainloop()
Esempio n. 13
0
class ScrollFrame(Frame):  # https://gist.github.com/mp035/9f2027c3ef9172264532fcd6262f3b01 by mp035
    def __init__(self, parent):
        super().__init__(parent)  # create a frame (self)

        self.canvas = Canvas(self, borderwidth=0, background='white')  # place canvas on self
        self.viewPort = Frame(self.canvas,
                              background='white')  # place a frame on the canvas, this frame will hold the child widgets
        self.vsb = Scrollbar(self, orient="vertical", command=self.canvas.yview)  # place a scrollbar on self
        self.vsb2 = Scrollbar(self, orient="horizontal", command=self.canvas.xview)
        self.canvas.configure(yscrollcommand=self.vsb.set)  # attach scrollbar action to scroll of canvas
        self.canvas.configure(xscrollcommand=self.vsb2.set)

        self.vsb.pack(side="right", fill="y")  # pack scrollbar to right of self
        self.vsb2.pack(side="bottom", fill="x")
        self.canvas.pack(side="left", fill="both", expand=True)  # pack canvas to left of self and expand to fil
        self.canvas_window = self.canvas.create_window((4, 4), window=self.viewPort, anchor="nw",
                                                       # add view port frame to canvas
                                                       tags="self.viewPort")

        self.viewPort.bind("<Configure>",
                           self.onFrameConfigure)  # bind an event whenever the size of the viewPort frame changes.

        self.onFrameConfigure(
            None)  # perform an initial stretch on render, otherwise the scroll region has a tiny border until the first resize

    def onFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        self.canvas.configure(scrollregion=self.canvas.bbox(
            "all"))  # whenever the size of the frame changes, alter the scroll region respectively.
Esempio n. 14
0
def _setup_canvas(table_frame,
                  data: List[List[str]],
                  column_widths: List[int] = None,
                  height=200,
                  width=None):
    if not column_widths:
        column_widths = _get_columns_widths(data)

    if not width:
        cells_width = sum(column_widths) * 8  # text len * char size
        cells_ipadx = len(column_widths) * 8  # inner padding
        # borders_width = len(column_widths)
        width = (cells_width + cells_ipadx)
        log.debug(f"got canvas width: {width}")
    canvas = Canvas(table_frame, borderwidth=0)
    canvas_frame = Frame(canvas)
    vsb = Scrollbar(table_frame, orient="vertical", command=canvas.yview)
    canvas.configure(yscrollcommand=vsb.set, width=width, heigh=height)
    vsb.pack(side="right", fill="y")
    canvas.pack(side="left", fill="both", expand=True)
    canvas.create_window((4, 4),
                         window=canvas_frame,
                         anchor="nw",
                         tags="frame")
    # be sure that we call OnFrameConfigure on the right canvas
    canvas_frame.bind("<Configure>",
                      lambda event, canvas=canvas: _OnFrameConfigure(canvas))

    _fill_data(canvas_frame, data, column_widths)
Esempio n. 15
0
def makeWindow():
    'create GUI'
    frame = Frame(width=100, height=100, background="blue")
    frame.bind("<Button-1>", handler)
    frame.bind('<Button-3>', handler2)
    frame.pack()
    frame.mainloop()
Esempio n. 16
0
class VerticalScrollGrid(Frame):
    def __init__(self, root):
        Frame.__init__(self, root)
        self.canvas = Canvas(root, borderwidth=0)
        self.frame = Frame(self.canvas)
        self.vsb = Scrollbar(root,
                             orient="vertical",
                             command=self.canvas.yview)
        self.canvas.configure(yscrollcommand=self.vsb.set)
        self.vsb.grid(row=0, column=1, sticky='NS')
        self.vsb.configure(command=self.canvas.yview)
        self.canvas.grid(row=0, column=0, sticky='NSEW')
        self.canvas.create_window((4, 4),
                                  window=self.frame,
                                  anchor="nw",
                                  tags="self.frame")
        self.frame.bind("<Configure>", self.onFrameConfigure)
        self.frame.bind_all("<MouseWheel>", self.on_mousewheel)
        # self.frame.bind("<Button-4>", self.on_mousewheel_up)
        # self.frame.bind("<Button-5>", self.on_mousewheel_down)
    def onFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

    # def on_mousewheel_down(self, event): self.canvas.yview_scroll(1, "units")
    # def on_mousewheel_up(self, event): self.canvas.yview_scroll(-1, "units")
    def on_mousewheel(self, event):
        self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")

    def go_to_top(self, event=None):
        self.canvas.yview_moveto(0)
Esempio n. 17
0
class VerticalScrollPack(Frame):
    def __init__(self, root):
        Frame.__init__(self, root)
        self.canvas = Canvas(root, borderwidth=0)
        self.frame = Frame(self.canvas)
        self.vsb = Scrollbar(root,
                             orient="vertical",
                             command=self.canvas.yview)
        self.canvas.configure(yscrollcommand=self.vsb.set)
        self.vsb.pack(side="right", fill="y")
        self.canvas.pack(side="left", fill="both", expand=True)
        self.canvas.create_window((4, 4),
                                  window=self.frame,
                                  anchor="nw",
                                  tags="self.frame")
        self.frame.bind("<Configure>", self.onFrameConfigure)
        self.frame.bind_all("<MouseWheel>", self.on_mousewheel)

    def onFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

    def on_mousewheel(self, event):
        self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")

    def go_to_top(self, event=None):
        self.canvas.yview_moveto(0)
Esempio n. 18
0
    def initUI(self):

        self.master.title("Window_Position")
        self.pack(fill=BOTH)
        for x in range(0, 100):
            self.rowconfigure(x, pad=5)
        for y in range(0, 100):
            self.columnconfigure(y, pad=5)

        info = Label(self, text="")
        info.grid(row=0, column=0, columnspan=5)
        self.info = info

        for x in range(0, self.rows):
            for y in range(0, self.columns):
                # img = PhotoImage(width=1, height=1)
                lbl = Frame(self, bg='#fff', width=95, height=95, 
                    cursor='hand2')
                lblId= 'x' + str(x) + 'y' + str(y)
                lbl.pos_attr= 'x' + str(x) + 'y' + str(y)
                lbl.row_attr=x
                lbl.col_attr=y
                lbl.posX=x*100
                lbl.posY=y*100
                # lbl.config(text = 'x:' + str(x) + ', y: ' + str(y)) 
                self.itemsMap[lblId] = lbl
                lbl.bind("<Enter>", func=lambda event, t=lblId: self.mouseover(event, t))
                lbl.bind("<Leave>", func=lambda event, t=lblId: self.mouseout(event, t))
                lbl.bind("<ButtonRelease-1>", func=lambda event, t=lblId: self.mouseup(event, t))
                lbl.bind("<Button-1>", func=lambda event, t=lblId: self.mousedown(event, t))
                lbl.bind("<B1-Motion>", func=lambda event, t=lblId: self.mousedrag(event, t))
                lbl.grid(row=y+1, column=x)


        self.pack()
Esempio n. 19
0
    def createCanvas(self):
       f = Frame(self)
       canvas = Canvas(f, width=self.canvasH, height=self.canvasH, bg='white')

       xbar = Scrollbar( f, orient='horizontal', command=canvas.xview )
       ybar = Scrollbar( f, orient='vertical', command=canvas.yview )
       canvas.configure( xscrollcommand=xbar.set, yscrollcommand=ybar.set )

       # Resize box
       resize = Label( f, bg='white' )
       # Layout
       canvas.grid( row=0, column=1, sticky='nsew')
       ybar.grid( row=0, column=2, sticky='ns')
       xbar.grid( row=1, column=1, sticky='ew' )
       resize.grid( row=1, column=2, sticky='nsew' )

       # Resize behavior
       f.rowconfigure( 0, weight=1 )
       f.columnconfigure( 1, weight=1 )
       f.grid( row=0, column=0, sticky='nsew' )
       f.bind( '<Configure>', lambda event: self.updateScrollRegion() )  

       # Mouse bindings

       canvas.bind( '<ButtonPress-1>', self.clickCanvas )
       canvas.bind( '<B1-Motion>', self.dragCanvas )
       canvas.bind( '<ButtonRelease-1>', self.releaseCanvas )
       
       return f, canvas
Esempio n. 20
0
def scroll_bar(mainframe):
    scroll = ttk.Scrollbar(mainframe, orient=VERTICAL)
    canvas = Canvas(mainframe,
                    scrollregion=(0, 0, 1000, 1200),
                    yscrollcommand=scroll.set)
    scroll['command'] = canvas.yview

    frame = Frame(canvas)
    frame_id = canvas.create_window((0, 0), window=frame, anchor='nw')
    ttk.Sizegrip(mainframe).grid(column=2, row=1, sticky=(S, E))

    canvas.grid(column=0, row=0, sticky=(N, W, E, S))
    scroll.grid(column=2, row=0, sticky=(N, S))

    # track changes to the canvas and frame width and sync them,
    # also updating the scrollbar
    def _configure_frame(event):
        # update the scrollbars to match the size of the inner frame
        size = (frame.winfo_reqwidth(), frame.winfo_reqheight())
        canvas.config(scrollregion="0 0 %s %s" % size)
        if frame.winfo_reqwidth() != canvas.winfo_width():
            # update the canvas's width to fit the inner frame
            canvas.config(width=frame.winfo_reqwidth())
        del event

    frame.bind('<Configure>', _configure_frame)

    def _configure_canvas(event):
        if frame.winfo_reqwidth() != canvas.winfo_width():
            # update the inner frame's width to fill the canvas
            canvas.itemconfigure(frame_id, width=canvas.winfo_width())
        del event

    canvas.bind('<Configure>', _configure_canvas)
    return frame
Esempio n. 21
0
def main():
    root = Tk()
    root.title("Rx for Python rocks")
    scheduler = TkinterScheduler(root)

    mousemove = Subject()

    frame = Frame(root, width=600, height=600)

    frame.bind("<Motion>", mousemove.on_next)

    text = 'TIME FLIES LIKE AN ARROW'

    def on_next(info):
        label, ev, i = info
        label.place(x=ev.x + i * 12 + 15, y=ev.y)

    def handle_label(label, i):
        label.config(dict(borderwidth=0, padx=0, pady=0))

        mapper = ops.map(lambda ev: (label, ev, i))
        delayer = ops.delay(i * 0.1)

        return mousemove.pipe(delayer, mapper)

    labeler = ops.flat_map_indexed(handle_label)
    mapper = ops.map(lambda c: Label(frame, text=c))

    rx.from_(text).pipe(mapper, labeler).subscribe(on_next,
                                                   on_error=print,
                                                   scheduler=scheduler)

    frame.pack()
    root.mainloop()
Esempio n. 22
0
class ScrollFrame(Frame):
    def __init__(self, parent):
        super().__init__(parent)  # create a frame (self)
        self.canvas = Canvas(self, borderwidth=0)  #place canvas on self
        self.viewPort = Frame(
            self.canvas
        )  #place a frame on the canvas, this frame will hold the child widgets
        self.vsb = Scrollbar(
            self, orient="vertical",
            command=self.canvas.yview)  #place a scrollbar on self
        self.canvas.configure(yscrollcommand=self.vsb.set
                              )  #attach scrollbar action to scroll of canvas

        self.vsb.pack(side="right", fill="y")  #pack scrollbar to right of self
        self.canvas.pack(
            side="left", fill="both",
            expand=True)  #pack canvas to left of self and expand to fil
        self.canvas.create_window(
            (4, 4),
            window=self.viewPort,
            anchor="nw",  #add view port frame to canvas
            tags="self.viewPort")
        self.viewPort.bind(
            "<Configure>", self.onFrameConfigure
        )  #bind an event whenever the size of the viewPort frame changes.

    def onFrameConfigure(self, event):
        '''Reset the scroll region to encompass the inner frame'''
        self.canvas.configure(
            scrollregion=self.canvas.bbox("all")
        )  #whenever the size of the frame changes, alter the scroll region respectively.
Esempio n. 23
0
def view_admin():
    try:
        admin_list = [session.query(Admin).filter_by(username="******").first()]
        admin_list += session.query(Admin).filter(
            Admin.username != "admin").all()
    except:
        messagebox.showerror("Error",
                             "Couldn't Fetch The Admins' Table From The DB")
        session.rollback()
        return

    subwindow = Toplevel(window)
    subwindow.title("Admins")
    subwindow.geometry("450x600+400+200")

    canvas = Canvas(subwindow)
    scrollable_frame = Frame(canvas)
    scrollable_frame.bind(
        "<Configure>",
        lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
    canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")

    scrollbary = Scrollbar(subwindow, orient="vertical", command=canvas.yview)
    scrollbarx = Scrollbar(subwindow,
                           orient="horizontal",
                           command=canvas.xview)

    canvas.configure(xscrollcommand=scrollbarx.set)
    canvas.configure(yscrollcommand=scrollbary.set)

    scrollbary.pack(side="right", fill="y")
    scrollbarx.pack(side="bottom", fill="x")
    canvas.pack(side="left", fill="both", expand=True)

    ttk.Label(scrollable_frame, text="index").grid(row=0,
                                                   column=0,
                                                   ipadx=5,
                                                   ipady=1)
    ttk.Label(scrollable_frame, text="UserName").grid(row=0,
                                                      column=1,
                                                      ipadx=5,
                                                      ipady=1)

    for i in range(len(admin_list)):
        ttk.Label(scrollable_frame, text=i + 1).grid(row=i + 1,
                                                     column=0,
                                                     ipadx=5,
                                                     ipady=1)
        ttk.Label(
            scrollable_frame,
            text=admin_list[i].username,
        ).grid(row=i + 1, column=1, ipadx=5, ipady=1)
        ttk.Button(
            scrollable_frame,
            text="Remove",
            command=lambda username=admin_list[i].username: remove_admin(
                username),
        ).grid(row=i + 1, column=7, ipadx=1, ipady=1)
Esempio n. 24
0
def create_window():
    '''Function to create a GUI window of 100x100 that checks the event of a
    left mouse click that occurs within the window.'''
    root = Tk()

    widget = Frame(root, width=100, height=100)
    widget.bind("<Button-1>", check)
    widget.pack()

    root.mainloop()
Esempio n. 25
0
def create_window():
    '''Function to create a GUI window of 100x100 that checks the event of a
    left mouse click that occurs within the window.'''
    root = Tk()

    widget = Frame(root, width=100, height=100)
    widget.bind("<Button-1>", check)
    widget.pack()

    root.mainloop()
Esempio n. 26
0
    def __init__(self):
        """
            À completer !.
        """
        super().__init__()

        # Nom de la fenêtre.
        self.title("Ultimate Tic-Tac-Toe")

        # La partie de ultimate Tic-Tac-Toe
        self.partie = Partie()

        # Un ditionnaire contenant les 9 canvas des 9 plateaux du jeu
        self.canvas_uplateau = {}

        Button(self.canvas_uplateau, text ='Débuter la partie', command =self.demande_confirmation).\
            grid(row =0, column =4)

        self.var = IntVar()
        Checkbutton(self, text= 'VS ordinateur', variable=self.var, onvalue =1, offvalue =0).grid(row =0, column =2)


        # L'entrée du joueur1 est automatiquement demandé
        Label(self.canvas_uplateau, text ="Nom du Joueur 1:").\
            grid(row =0, column =0, sticky=E)
        self.joueur1 = Entry(self.canvas_uplateau, width =14)
        self.joueur1.grid(row =0, column =1, padx=5, pady=5, sticky=E+W)

#        Label (self.canvas_uplateau, text="Le tour: {}".format(self.partie.joueur_courant.nom)).grid(row=3, column=3)

        # L'entrée du joueur2 est selon la checkbox (peut etre l'ordinateur
        Label(self.canvas_uplateau, text ="Nom du Joueur 2:").\
            grid(row =1, column =0, sticky=E)
        self.joueur2 = Entry(self.canvas_uplateau, width =14)
        self.joueur2.grid(row =1, column =1, padx=5, pady=5, sticky=E+W)

        Button(self.canvas_uplateau, text = 'Quitter', command = self.quit).\
            grid (row = 5, column = 4, sticky = E)

        # Création des frames et des canvas du jeu
        for i in range(0, 3):
            for j in range(0, 3):
                cadre = Frame(self, borderwidth=5, relief=GROOVE, background = '#e1e1e1')
                cadre.grid(row=i+3, column=j, padx=5, pady=5)
                cadre.bind('<Enter>', self.entrer_frame)
                cadre.bind('<Leave>', self.sortir_frame)
                self.canvas_uplateau[i,j] = CanvasPlateau(cadre, self.partie.uplateau[i,j])
                self.canvas_uplateau[i,j].grid()
                # On lie un clic sur le Canvas à une méthode.
                self.canvas_uplateau[i,j].bind('<Button-1>', self.selectionner)

        # Ajout d'une étiquette d'information.
        self.messages = Label(self)
        self.messages.grid(columnspan=3)
Esempio n. 27
0
class StateExam(Frame):
    def __init__(self, master, center_exam: CenterExam,
                 footer_exam: FooterExam, **kw):
        super().__init__(master=master)
        self.master = master
        self.center_exam = center_exam
        self.footer_exam = footer_exam
        self.setupUI()

    def setupUI(self):
        self.canvas = Canvas(self)

        self.scrollbar = Scrollbar(self)
        self.scrollbar['orient'] = 'vertical'
        self.scrollbar['command'] = self.canvas.yview
        self.scrollbar.pack(side='right', fill='y')

        self.canvas['yscrollcommand'] = self.scrollbar.set
        self.canvas.pack(side='left')

        self.frame = Frame(self.canvas)
        self.frame.bind("<Configure>", self.resizeCanvas)
        self.canvas.create_window((0, 0), window=self.frame, anchor='center')
        self.addStatusButton()

    def resizeCanvas(self, event):
        self.canvas['scrollregion'] = self.canvas.bbox(
            'all')  # width button inside and height is center_exam's height
        self.canvas['width'] = event.width
        self.canvas['height'] = 150

    def addStatusButton(self):
        self.listStateButton = []
        for question in self.center_exam.listQuestionObjects:
            b = StatusButton(self.frame,
                             question,
                             center_exam=self.center_exam,
                             footer_exam=self.footer_exam)
            self.listStateButton.append(b)
            b.pack(fill='x')

    def checkQuestionState(self):
        '''continuously check the status of questions to display the appropriate icon'''
        self.icons = {
            'no': 'icon/question-24.png',
            'mark': 'icon/flag.png',
            'sure': 'icon/tick-24.png'
        }
        while True:
            for b in self.listStateButton:
                b.answer['text'] = b.question.getAnswer()
                photo = PhotoImage(file=self.icons[b.question.state])
                b.statusIcon['image'] = photo
                b.statusIcon.image = photo
Esempio n. 28
0
class Titlebar:
    def __init__(self, root, title="Titlebar"):
        self.title = title
        self.root = root
        self.root.update()
        self.geometry = self.root.wm_geometry()

        #Widgets:
        self.bar = Frame(self.root, bg="blue")
        self.body = Frame(self.root, bg="red")

        self.label = Label(self.bar, text=self.title)
        self.close_btn = Button(self.bar, text="X", command=self.root.destroy)
        self.max_btn = Button(self.bar, text="[]")
        self.min_btn = Button(self.bar, text="_")

        #Layout
        self.root.rowconfigure(1, weight=1)
        self.root.columnconfigure(0, weight=1)
        self.bar.columnconfigure(0, weight=1)

        self.bar.grid(row=0, column=0, sticky="new")
        self.body.grid(row=1, column=0, sticky="nsew")

        self.label.grid(row=0, column=0, sticky="w")
        self.min_btn.grid(row=0, column=1)
        self.max_btn.grid(row=0, column=2)
        self.close_btn.grid(row=0, column=3)

        # Geometry / Bindings
        self.delta_x, self.delta_y = 0, 0

        self.bar.bind("<Button-1>", self.get_position)
        self.bar.bind("<B1-Motion>", self.move_window)

        self.titlebar()

    def titlebar(self):
        self.root.overrideredirect(True)
        self.root.geometry(self.geometry)

    def get_position(self, event):
        window_x = self.root.winfo_x()
        window_y = self.root.winfo_y()

        cursor_x = event.x_root
        cursor_y = event.y_root

        self.delta_x = cursor_x - window_x
        self.delta_y = cursor_y - window_y

    def move_window(self, event):
        self.root.geometry(
            f"+{event.x_root - self.delta_x}+{event.y_root - self.delta_y}")
Esempio n. 29
0
class StickyNotes(Toplevel):
    def __init__(self, master, **kwargs):
        super().__init__(master, **kwargs)
        self.xclick = 0
        self.yclick = 0

        # master (root) window
        self.overrideredirect(True)
        global no_of_windows
        self.geometry('350x450+' + str(1000+no_of_windows*(-30)) + '+' + str(100 + no_of_windows*20))
        self.config(bg = '#838383')
        self.attributes('-topmost', 'true')
        self.resizable(True,True)

        # titlebar
        self.titlebar = Frame(self , bg = '#F8F796', relief = 'flat', bd = 2)
        self.titlebar.bind('<Button-1>', self.get_pos)
        self.titlebar.bind('<B1-Motion>', self.move_window)
        self.titlebar.pack(fill = X, expand = 1, side = TOP)

        self.closebutton = Label(self.titlebar, text = 'X', bg = '#F8F7B6', relief = 'flat')
        self.closebutton.bind('<Button-1>', self.quit_window)
        self.closebutton.pack(side = RIGHT)

        self.newbutton = Label(self.titlebar, text = '+', bg = '#F8F7B6', relief = 'flat')
        self.newbutton.pack(side = LEFT)
        self.newbutton.bind('<Button-1>', self.another_window)

        self.mainarea = tkst.ScrolledText(self, bg = '#FDFDCA', font=('Comic Sans MS', 14, 'italic'), relief = 'flat', padx = 5, pady = 10)
        self.mainarea.pack(fill = BOTH, expand = 1)

        
        no_of_windows += 1

    def get_pos(self, event):
        self.xclick = event.x
        self.yclick = event.y

    def move_window(self, event):
        self.geometry('+{0}+{1}'.format(event.x_root-self.xclick, event.y_root-self.yclick))

    def another_window(self, event):
        StickyNotes(root)

    def quit_window(self, event):
        self.closebutton.config(relief = 'flat', bd = 0)
        if(messagebox.askyesno('Delete Note?','Are you sure you want to delete this note?', parent = self)):
            global no_of_windows
            self.destroy()
            no_of_windows -= 1
            if(no_of_windows == 1):
                root.destroy()
            return
        self.closebutton.config(relief = 'flat', bd = 0, bg = '#F8F7B6')
Esempio n. 30
0
def createScrollFrame(levelTop, color):
    canvas = Canvas(levelTop, borderwidth=0, bg="#FFC0CB")
    frame = Frame(canvas, background="#FFC0CB")
    vsb = Scrollbar(levelTop, orient="vertical", command=canvas.yview)
    canvas.configure(yscrollcommand=vsb.set)

    vsb.pack(side="right", fill="y")
    canvas.pack(side="left", fill="both", expand=True)
    canvas.create_window((4, 4), window=frame, anchor="nw")

    frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
    return frame
Esempio n. 31
0
def main():
    window = Tk()

    window.title("AI-GAME")
    window.geometry("1080x720")
    m_frame = Frame(window).pack()
    s_frame = Frame(window).pack(side='bottom')
    c_t = create_track(m_frame, None, None)
    c_t.create_line()
    m_frame.bind("<Button-1>", callback)
    m_frame.pack()
    window.mainloop()
Esempio n. 32
0
 def CreateHighlight(self, fwParent, fnImage, ixRow, ixCol):
     psWidth = self.psIconWidth + (2 * self.psBorder)
     psHeight = self.psIconHeight + (2 * self.psBorder)
     fwHilit = Frame(fwParent,
                     borderwidth=0,
                     width=psWidth,
                     height=psHeight)
     if fnImage == self.svPicked.get():
         fwHilit.configure(background=HIGHLIGHT_COL)
     fwHilit.grid(row=(ixRow * 3), column=(ixCol * 2))
     fwHilit.bind("<Button-1>",
                  lambda event, a=fnImage: self.ClickedIcon(a))
     return fwHilit
Esempio n. 33
0
    def config_frame(self):
        frame_canvas = LabelFrame(self,
                                  text='Config',
                                  width=self.windows_size[0],
                                  height=self.windows_size[1] - 200
                                  )
        frame_canvas.grid_rowconfigure(0, weight=1)
        frame_canvas.grid_columnconfigure(0, weight=1)
        frame_canvas.grid_propagate(False)

        # Add a canvas in that frame
        canvas = Canvas(frame_canvas)
        canvas.grid(row=0, column=0, sticky=N+W)

        # Link a scrollbar to the canvas

        def on_mousewheel(event):
            canvas.yview_scroll(int(-1*(event.delta/120)), "units")

        def bound_to_mousewheel(event):
            canvas.bind_all("<MouseWheel>", on_mousewheel)

        def unbound_to_mousewheel(event):
            canvas.unbind_all("<MouseWheel>")

        y_scrollbar = Scrollbar(frame_canvas, orient="vertical", command=canvas.yview)
        y_scrollbar.grid(row=0, column=1, sticky='ns')
        canvas.configure(yscrollcommand=y_scrollbar.set)

        inner_frame = Frame(canvas)
        inner_frame.bind('<Enter>', bound_to_mousewheel)
        inner_frame.bind('<Leave>', unbound_to_mousewheel)

        canvas.create_window((0, 0), window=inner_frame, anchor='nw')

        for i in range(len(atf.bot_config_title_fns)):
            title_fns, sub_fns = atf.bot_config_title_fns[i]
            check = section_frame(
                self,
                inner_frame,
                title_fns,
                sub_fns
            )
            check.grid(row=i, column=0, sticky=N + W)

        inner_frame.update_idletasks()

        frame_canvas.config(width=self.windows_size[0] - 20, height=self.windows_size[1] - 350)
        canvas.config(width=self.windows_size[0] - 20, height=self.windows_size[1] - 350, scrollregion=canvas.bbox("all"))

        return frame_canvas
Esempio n. 34
0
def additems(i, doreturn=False, bgcolor="#555"):
	returnable = []
	for item in i:
		global totalitems
		totalitems += 1
		ff = Frame(f, bg=bgcolor)
		item.body = item.author.name + ' || ' + item.fullname + '\n' + item.body
		item.body = str(totalitems) + '\n' + item.body
		ibody = item.body.replace('\n\n', '\n')
		ifinal = ''
		for paragraph in ibody.split('\n'):
			ifinal += '\n'.join(textwrap.wrap(paragraph))
			ifinal += '\n'  
	
		item.body = ifinal
		ww = 680
		wh = 10 
		wx = 20
		wy = 20 
		#print(ww, wh, wx, wy)
		ff.ww = ww
		ff.wh = wh
		ff.wx = wx
		ff.wy = wy
		ff.body = item.body
		ff.sourceitem = item
		ff.configure(width=ww, height=wh)
		ff.place(x=wx, y=wy)
		ff.bind("<B1-Motion>", framedrag)
		ff.bind("<ButtonRelease-1>", resetdrag)
		ff.pack_propagate(0)
		l = Label(ff, text=item.body, bg="#777")
		l.place(x=10,y=10)
		rt = Text(ff, width= 15, height= (len(ifinal.split('\n'))) - 2)
		rt.sourceitem = item
		rt.place(x=400,y=10)
		rb = Button(ff, text="Reply", command= lambda rep=rt: reply(rep))
		rb.place(x=400,y=wh-20)
		ff.rt = rt
		ff.rb = rb
		if not doreturn:
			widgets.append(ff)
		else:
			returnable.append(ff)
	if doreturn:
		return returnable
	else:
		refreshscreen()
def main():
    root = Tk()
    root.title("Rx for Python rocks")
    scheduler = TkinterScheduler(root)

    mousemove = Subject()

    frame = Frame(root, width=600, height=600)

    frame.bind("<Motion>", mousemove.on_next)

    text = 'TIME FLIES LIKE AN ARROW'

    def on_next(info):
        label, ev, i = info
        label.place(x=ev.x + i*12 + 15, y=ev.y)

    def handle_label(label, i):
        label.config(dict(borderwidth=0, padx=0, pady=0))

        mapper = ops.map(lambda ev: (label, ev, i))
        delayer = ops.delay(i*0.1)

        return mousemove.pipe(
            delayer,
            mapper
        )

    labeler = ops.flat_map_indexed(handle_label)
    mapper = ops.map(lambda c: Label(frame, text=c))

    rx.from_(text).pipe(
        mapper,
        labeler
    ).subscribe(on_next, on_error=print, scheduler=scheduler)

    frame.pack()
    root.mainloop()
Esempio n. 36
0
class View():
    """This calls contains all the tkinter specific code"""

    def __init__(self, control, master):
        """View constructor"""
        self.control = control  # Link back to talk to controller
        self.master = master
        master.wm_state('zoomed')  # Full screen. Might not work on Mac
        self.frame = Frame(master)

        self.create_menus()
        self.create_context_menus()
        self.create_toolbar()

        self.frame.pack(fill=BOTH, expand=YES)
        self.frame.focus_set()
        
        self.create_events()

    def create_menus(self):
        """creates the menus"""
        # main menu
        menubar = Menu(self.master)

        # file menus
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="New", accelerator="^N",
                             command=self.control.cmd_new)
        filemenu.add_command(label="Open", accelerator="^O",
                             command=self.control.cmd_open)
        filemenu.add_command(label="Save", accelerator="^S",
                             command=self.control.cmd_save)
        filemenu.add_command(label="Save as",
                             command=self.control.cmd_save_as)
        filemenu.add_separator()
        filemenu.add_command(label="Exit",
                             command=self.control.cmd_exit)
        menubar.add_cascade(label="File", menu=filemenu)

        # edit menus
        editmenu = Menu(menubar, tearoff=0)
        editmenu.add_command(label="Undo", accelerator="^Z",
                             command=self.control.cmd_null)
        editmenu.add_command(label="Redo", accelerator="^C",
                             command=self.control.cmd_null)
        editmenu.add_separator()
        editmenu.add_command(label="Cut", accelerator="^X",
                             command=self.control.cmd_null)
        editmenu.add_command(label="Copy", accelerator="^C",
                             command=self.control.cmd_null)
        editmenu.add_command(label="Paste", accelerator="^V"
                             , command=self.control.cmd_null)
        editmenu.add_separator()
        editmenu.add_command(label="Delete",
                             command = self.control.cmd_null)
        editmenu.add_separator()
        editmenu.add_command(label="Select all",
                             command = self.control.cmd_null)
        menubar.add_cascade(label="Edit", menu=editmenu)

        # drawing menus
        drawingmenu = Menu(menubar, tearoff=0)
        drawingmenu.add_command(label="Select",
                                command=self.control.cmd_null)
        drawingmenu.add_command(label="Line",
                                command=self.control.cmd_line)
        drawingmenu.add_command(label="Rectangle",
                                command=self.control.cmd_rectangle)
        drawingmenu.add_command(label="Circle",
                                command=self.control.cmd_circle)
        drawingmenu.add_command(label="Group",
                                command=self.control.cmd_null)
        drawingmenu.add_command(label="Instance",
                                command=self.control.cmd_null)
        menubar.add_cascade(label="Drawing", menu=drawingmenu)

        # toolbar menus
        toolbarmenu = Menu(menubar, tearoff=0)
        toolbarmenu.add_checkbutton(label='Tools',
                                    command=self.control.cmd_tools)
        menubar.add_cascade(label="Toolbar", menu=toolbarmenu)

        # help menus
        helpmenu = Menu(menubar, tearoff=0)
        helpmenu.add_command(label="About",
                             command = self.control.cmd_null)
        menubar.add_cascade(label="Help", menu = helpmenu)

        self.master.config(menu=menubar)  # lock in menubar

    def create_context_menus(self):
        """Creates the connects menus, i.e. for right click"""
        self.context = Menu(self.master, tearoff=0)
        self.context.add_command(label="Dirty",
                                 command=self.control.cmd_dirty)
        self.context.add_command(label="Clean",
                                 command=self.control.cmd_clean)

    def create_toolbar(self):
        """Creates toolbar, hopefully floating dockable but not yet"""
        self.toolbar = Frame(self.master, bd=1, relief=RAISED)

        self.img = Image.open("exit.png")
        eimg = ImageTk.PhotoImage(self.img)  

        exitButton = Button(self.toolbar, image=eimg, bd=1,
                            relief=RAISED, command=self.control.cmd_exit)
        exitButton.image = eimg
        exitButton.pack(side=TOP, padx=2, pady=2)

        anotherButton = Button(self.toolbar, image=eimg, bd=1,
                               relief=RAISED, command=self.control.cmd_null)
        anotherButton.image = eimg
        anotherButton.pack(side=TOP, padx=2, pady=2)

        anotherButton = Button(self.toolbar, image=eimg, bd=1,
                               relief=RAISED, command=self.control.cmd_null)
        anotherButton.image = eimg
        anotherButton.pack(side=TOP, padx=2, pady=2)

        self.toolbar.pack(side=LEFT, fill=Y)
        
    def create_events(self):
        """Binds keyboard events to handlers"""
        self.frame.bind("<Control-o>", self.key_open)
        self.frame.bind("<Control-s>", self.key_save)
        self.frame.bind("<Button-1>", self.left_click)
        self.frame.bind("<Button-3>", self.right_click)
        self.frame.bind("<Configure>", self.on_resize)

        # Window closing event
        self.master.protocol('WM_DELETE_WINDOW', self.control.cmd_exit)

    def on_resize(self,e):
        """Called when window changes size"""
        pass

    @staticmethod
    def question_box(title, text):
        """Just a wrapped for tkinter so command calls can be tkinter independent"""
        return messagebox.askquestion(title, text) == "yes"

    @staticmethod
    def warning_box(title, text):
        """Just a wrapped for tkinter so command calls can be tkinter independent"""
        messagebox.showwarning(title, text)

    @staticmethod
    def info_box(title, text):
        """Just a wrapped for tkinter so command calls can be tkinter independent"""
        messagebox.showinfo(title, text)

    @staticmethod
    def open_file_dialog():
        """Just a wrapped for tkinter so command calls can be tkinter independent"""
        return filedialog.askopenfilename(filetypes=(("Gcode","*.gcode"), ("All files","*.*")))

    @staticmethod
    def save_file_dialog(initial_file):
        """Just a wrapped for tkinter so command calls can be tkinter independent"""
        return filedialog.asksaveasfile(mode='w',
                                        initialfile=initial_file,
                                        filetypes=(("Gcode","*.gcode"),("All files","*.*")),
                                        defaultextension=".gcode")

    def key_open(self, e):
        self.control.cmd_open()

    def key_save(self, e):
        self.control.cmd_open()

    def left_click(self, e):
        self.control.cmd_left_click(e.x_root, e.y_root)


    def right_click(self, e):
        self.control.cmd_right_click(e.x_root, e.y_root)
        
    def show_context_menu(self, x, y):
        self.context.tk_popup(x, y, 0)

    def show_toolbar(self):
        # self.frame = Frame(self.master)

        self.create_menus()
        self.create_context_menus()
        self.create_toolbar()
        self.create_toolbar()
        self.create_toolbar()
        self.frame.pack(fill=BOTH, expand=YES)
        self.frame.focus_set()
        
        self.create_events()

    def hide_toolbar(self):
        self.toolbar.pack_forget()
Esempio n. 37
0
    def __init__(self):
        """
            Methode speciale initialisant une nouvelle fenêtre de jeu Ultimate Tic-Tac-Toe.
        """
        super().__init__()

        # Nom de la fenêtre.
        self.title("Ultimate Tic-Tac-Toe")

        # La partie de ultimate Tic-Tac-Toe
        self.partie = Partie()

        # Un ditionnaire contenant les 9 canvas des 9 plateaux du jeu
        self.canvas_uplateau = {}

        # Création de deux joueurs.
        self.JoueursDuJeux()
        Popup()

        # Création des frames et des canvas du jeu
        for i in range(0, 3):
            for j in range(0, 3):
                cadre = Frame(self, borderwidth=5, relief=GROOVE, background = '#e1e1e1')
                cadre.grid(row=i, column=j, padx=5, pady=5)
                cadre.columnconfigure(0, weight=1)
                cadre.rowconfigure(0, weight=1)
                cadre.columnconfigure(1, weight=1)
                cadre.rowconfigure(1, weight=1)
                cadre.columnconfigure(2, weight=1)
                cadre.rowconfigure(2, weight=1)
                #cadre.columnconfigure(j, weight=1)
                #cadre.rowconfigure(i, weight=1)

                #Dessiner le cadre en jaune si la sourie entre dans le cadre
                cadre.bind('<Enter>', self.entrer_frame)
                cadre.bind('<Leave>', self.sortir_frame)

                self.canvas_uplateau[i, j] = CanvasPlateau(cadre, self.partie.uplateau[i, j])
                self.canvas_uplateau[i, j].grid()

                # On lie un clic sur le Canvas à une méthode.
                self.canvas_uplateau[i, j].bind('<Button-1>', self.selectionner)


        #Pour redimensionner automatiquement la fenêtre principale

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(2, weight=1)
        self.grid_rowconfigure(2, weight=1)

        # Ajout d'une étiquette d'information.
        self.messages = Label(self)
        self.messages.grid(column=0, row=4, columnspan=3)
        # Ajout d'une étiquette pour le nom des joueurs.
        self.labNoms = Label(self)
        self.labNoms.grid(column=0, row=5)
        # Ajout d'une étiquette pour la date et le chronometre.
        self.labDate = Label(self)
        self.labDate.grid(column=0, row=6)


        # Les bouttons en dessous
        B1 = Button(self, text='Règles', width=15, command=self.regles).grid(row=7,column=0)
        B2 = Button(self, text='Nouvelle Partie', width=15, command=self.nouvellePartie).grid(row=7, column=1)
        B3 = Button(self, text='Statistiques', width=15, command=self.statistiques).grid(row=7, column=2)
        B4 = Button(self, text='Historique', width=15, command=self.regles).grid(row=8, column=1)
        B5 = Button(self, text='Quitter', width=5, command=self.quitter).grid(row=8, column=2)
        B5 = Button(self, text='Tout recommencer', width=15, command=self.regles).grid(row=8, column=0)
Esempio n. 38
0
class mainGUI(Frame, bootloader, GuiController):
    """ Contains the main view for the application """

    def __init__(self):
        """ Create the initial application GUI environment (tool bars, and other static elements) """
        Frame.__init__(self, self.root)
        self.thread_entry_field = ''  # Hold both search string, and drives autoRefresh logic

        self.menuBar = Menu()
        self.fileMenu = Menu(self.menuBar, tearoff=0)
        self.menuBar.add_cascade(label="File", menu=self.fileMenu, underline=1)
        self.fileMenu.add_command(label="Quit", command=self.root.destroy, underline=1)

        self.optionsMenu = Menu(self.menuBar, tearoff=0)
        self.menuBar.add_cascade(label="Options", menu=self.optionsMenu)
        self.optionsMenu.add_command(label="Settings", command=self.editSettings, underline=1)
        self.helpMenu = Menu(self.menuBar, tearoff=0)
        self.menuBar.add_cascade(label="Help", menu=self.helpMenu)
        self.helpMenu.add_command(label="Help", command=self.program_help, underline=1)
        self.helpMenu.add_command(label="About", command=self.program_about, underline=1)
        self.master.config(menu=self.menuBar)

        self.topFrame = Frame()
        self.thread_entry_box = Entry(self.topFrame)
        self.thread_entry_box.insert(0, self.DEFAULT_THREAD_TEXT)
        self.thread_entry_box.bind('<Return>', lambda event: self.add_thread_GUI())
        # Bind needs to send the event to the handler
        self.thread_entry_box.pack(side='left', fill='x', expand='True', padx=5)

        self.add_thread_btn = Button(self.topFrame)
        self.add_thread_btn['text'] = 'Add New Thread'
        self.add_thread_btn['command'] = lambda: self.add_thread_GUI()
        self.add_thread_btn.pack(side='left', padx=0)

        self.topFrame.pack(fill='x')

        self.create_thread_frame()

    def create_thread_frame(self):
        """ Sets up the main thread frame (where the magic happens) """

        # Sets up frame
        self.thread_list_canvas = Canvas(self.root, borderwidth=0)
        self.thread_list_frame = Frame(self.thread_list_canvas)

        # Creates scroll bar
        self.vsb = Scrollbar(self.root, orient="vertical", command=self.thread_list_canvas.yview)
        self.thread_list_canvas.configure(yscrollcommand=self.vsb.set)
        self.vsb.pack(side="right", fill="y")

        self.hsb = Scrollbar(self.root, orient="horizontal", command=self.thread_list_canvas.xview)
        self.thread_list_canvas.configure(xscrollcommand=self.hsb.set)
        self.hsb.pack(side="bottom", fill="x")

        # Packs frame
        self.thread_list_canvas.pack(side="left", fill="both", expand=True)
        self.thread_list_canvas.create_window((4, 4), window=self.thread_list_frame, anchor="nw", tags="self.frame")
        self.thread_list_frame.bind("<Configure>", self.OnFrameConfigure)

        self.create_thread_list_box()

    def OnFrameConfigure(self, event):
        """Reset the scroll region to encompass the inner frame"""
        self.thread_list_canvas.configure(scrollregion=self.thread_list_canvas.bbox("all"))

    # noinspection PyAttributeOutsideInit
    def create_thread_list_box(self):
        """ Creates the message list box for the create method """

        def hover_on(widget):
            widget['fg'] = 'dark blue'
            # widget['underline'] = True

        def hover_off(widget):
            widget['fg'] = 'black'
            # widget['underline'] = False

        for individual_thread in self.MESSAGE_THREADS:  # Fetch Message List from model

            if individual_thread.is_valid_thread():
                self.bg_color = 'green'
            else:
                self.bg_color = 'red'

            self.individual_thread_frame = Frame(self.thread_list_frame,
                                                 bg=self.bg_color)  # Create frame for each thread

            rowToInsertAt = self.MESSAGE_THREADS.index(individual_thread)

            self.text_color = 'black'
            self.threadText = Label(self.individual_thread_frame, bg=self.bg_color, fg=self.text_color)
            self.threadText['text'] = "[ Thread #:  " + individual_thread.threadId + " ]"

            self.threadText.bind("<Enter>", lambda event, text=self.threadText: hover_on(text))
            self.threadText.bind("<Leave>", lambda event, text=self.threadText: hover_off(text))

            self.threadText.bind("<Button-1>",
                                 lambda event, thread_in=individual_thread: self.open_in_web_browser(thread_in))
            self.threadText.grid(column=0, row=0, sticky='w', padx=0)

            self.image_count_text = Label(self.individual_thread_frame, bg=self.bg_color)
            num_of_images = individual_thread.get_number_of_images()
            if 0 < int(num_of_images) < 10:  # Format padding
                num_of_images = '00' + num_of_images
            if 10 < int(num_of_images) < 100:  # Format padding
                num_of_images = '0' + num_of_images

            self.image_count_text['text'] = "  [ # Images: " + num_of_images + " ]"
            self.image_count_text.bind("<Enter>", lambda event, text=self.image_count_text: hover_on(text))
            self.image_count_text.bind("<Leave>", lambda event, text=self.image_count_text: hover_off(text))

            self.image_count_text.bind("<Button-1>",
                                       lambda event, thread_in=individual_thread: self.open_in_file_browser(thread_in))

            self.image_count_text.grid(column=1, row=0, sticky='e', padx=0)

            self.deleteButton = Button(self.individual_thread_frame)
            self.deleteButton['text'] = 'Delete'
            self.deleteButton['command'] = lambda thread_in=individual_thread: self.delete_thread_GUI(thread_in)
            self.deleteButton.grid(column=2, row=0, sticky='e', padx=0)

            self.individual_thread_frame.grid(row=rowToInsertAt, sticky='w', pady=2)

    @staticmethod
    def open_in_file_browser(individual_thread):
        logging.debug(os.getcwd() + os.sep + individual_thread.threadId)
        if os.name == "nt":
            subprocess.Popen('explorer "' + os.getcwd() + os.sep + individual_thread.threadId + '"')

    @staticmethod
    def open_in_web_browser(individual_thread):
        webbrowser.open(
            url="http://boards.4chan.org/" + individual_thread.board + "/thread/" + individual_thread.threadId, new=2)

    def add_thread_GUI(self):
        entry_box_text = str(self.thread_entry_box.get())
        if entry_box_text not in self.MESSAGE_THREADS and entry_box_text != self.DEFAULT_THREAD_TEXT \
                and entry_box_text.isnumeric():
            try:
                self.add_thread(entry_box_text.strip(' '))
            except ThreadNotFound:
                messagebox.showwarning(message="Thread Not Found")
        else:
            messagebox.showwarning(message="Please enter a valid new thread ID")
        self.thread_entry_box.select_range(start=0, end=99)
        # Selects the contents so the user can just type the next message
        self.refresh_GUI()

    def delete_thread_GUI(self, thread_in):
        self.delete_thread(thread_in)
        self.refresh_GUI()

    def refresh_GUI(self):
        """ Refreshes the message list AND GUI window (used by auto refresh)"""
        self.refresh_thread_list()
        self.refresh_GUI_Window()

    def refresh_GUI_Window(self):
        """ Refreshes just the GUI window"""
        self.thread_list_canvas.destroy()
        self.vsb.destroy()
        self.hsb.destroy()
        self.create_thread_frame()

    @staticmethod
    def program_about():
        message = settings.__desc__ + '\n' + settings.__version__
        messagebox.showinfo(title='About', message=message)

    @staticmethod
    def program_help():
        message = 'See readme.md'
        messagebox.showinfo(title='About', message=message)
Esempio n. 39
0
class Preferences(Frame):
    def __init__(self, master, valves):
        Frame.__init__(self, master, bg='sky blue', width=1366, height=768)
        self.master = master

        self.canvas = Canvas(self, height=640, width=1300, bg='sky blue')
        self.frame = Frame(self.canvas, bg='sky blue')
        self.frame.bind('<Button-1>', self.process_click_out)

        self.scrollbar = Scrollbar(self, orient='vertical', command=self.canvas.yview)
        self.scrollbar.configure(activebackground='DarkRed', background='red', width=40)
        self.canvas.configure(yscrollcommand=self.scrollbar.set, scrollregion=[0, 0, 1366, 2100])

        self.scrollbar.pack(side='right', fill='y')
        self.canvas.pack(side='left')
        self.canvas.create_window((0, 0), window=self.frame, anchor='nw')

        self.keyboard = Keyboard(self.master)

        self.valves = valves
        self.frame.config(bg='sky blue')
        
        index = 0
        while index < 25:
            self.frame.grid_rowconfigure(index, minsize=80)
            self.frame.grid_columnconfigure(index, minsize=150)
            index += 1

        num_label = [Label(self.frame, text='1'),
                     Label(self.frame, text='2'),
                     Label(self.frame, text='3'),
                     Label(self.frame, text='4'),
                     Label(self.frame, text='5'),
                     Label(self.frame, text='6'),
                     Label(self.frame, text='7'),
                     Label(self.frame, text='8'),
                     ]
        row = 1
        for each in num_label:
            each.grid(row=row, column=0)
            each.config(width=3, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4')
            row += 3

        text_label = [Label(self.frame, text='VALVE 1:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 2:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 3:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 4:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 5:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 6:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 7:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: '),

                     Label(self.frame, text='VALVE 8:  '),
                     Label(self.frame, text='ACTION A: '),
                     Label(self.frame, text='ACTION B: ')

                     ]
        row = 1
        for each in text_label:
            each.grid(row=row, column=1)
            each.config(width=12, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4')
            row += 1

        self.valve_label = [Label(self.frame, textvariable=self.valves[0].get_name()),
                            Label(self.frame, textvariable=self.valves[1].get_name()),
                            Label(self.frame, textvariable=self.valves[2].get_name()),
                            Label(self.frame, textvariable=self.valves[3].get_name()),
                            Label(self.frame, textvariable=self.valves[4].get_name()),
                            Label(self.frame, textvariable=self.valves[5].get_name()),
                            Label(self.frame, textvariable=self.valves[6].get_name()),
                            Label(self.frame, textvariable=self.valves[7].get_name())]
        row = 1 
        for each in self.valve_label:
            each.grid(row=row, column=2)
            each.config(width=12, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4', anchor='w')
            each.bind('<Button-1>', self.process_click_out)
            row += 3

        self.entry_field = [Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),

                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),

                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text=''),
                            Entry(self.frame, text='')
                            ]
        row = 1
        for each in self.entry_field:
            each.grid(row=row, column=3)
            each.config(width=12, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4')
            each.bind('<Button-1>', self.process_click_in)
            row += 1

        self.action_a_label = [Label(self.frame, textvariable=self.valves[0].get_action_a()),
                               Label(self.frame, textvariable=self.valves[1].get_action_a()),
                               Label(self.frame, textvariable=self.valves[2].get_action_a()),
                               Label(self.frame, textvariable=self.valves[3].get_action_a()),
                               Label(self.frame, textvariable=self.valves[4].get_action_a()),
                               Label(self.frame, textvariable=self.valves[5].get_action_a()),
                               Label(self.frame, textvariable=self.valves[6].get_action_a()),
                               Label(self.frame, textvariable=self.valves[7].get_action_a())
                               ]
        row = 2
        for each in self.action_a_label:
            each.grid(row=row, column=2)
            each.config(width=12, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4', anchor='w')
            each.bind('<Button-1>', self.process_click_out)
            row += 3

        self.action_b_label = [Label(self.frame, textvariable=self.valves[0].get_action_b()),
                               Label(self.frame, textvariable=self.valves[1].get_action_b()),
                               Label(self.frame, textvariable=self.valves[2].get_action_b()),
                               Label(self.frame, textvariable=self.valves[3].get_action_b()),
                               Label(self.frame, textvariable=self.valves[4].get_action_b()),
                               Label(self.frame, textvariable=self.valves[5].get_action_b()),
                               Label(self.frame, textvariable=self.valves[6].get_action_b()),
                               Label(self.frame, textvariable=self.valves[7].get_action_b())
                               ]

        row = 3
        for each in self.action_b_label:
            each.grid(row=row, column=2)
            each.config(width=12, font=('Lucida Console', 30), bg='sky blue', fg='RoyalBlue4', anchor='w')
            each.bind('<Button-1>', self.process_click_out)
            row += 3

        self.lock()

    def process_click_out(self, event):
        self.canvas.configure(height=660)
        self.keyboard.grid_forget()

    def process_click_in(self, event):
        index = 0
        for each in self.entry_field:
            if each == event.widget:
                break
            index += 1

        if event.widget.cget('state') == 'normal':
            self.canvas.configure(height=250)
            self.keyboard.grid(row=2, column=0)
            self.keyboard.set_entry(event.widget)
            self.canvas.yview_moveto(index / 28)

    def lock(self):
        for each in self.entry_field:
            each.config(state='disabled')
Esempio n. 40
-1
 def initUI(self):
     #top frame using all the remaining space
     innerTopFrame = Frame(self, background="black")
     innerTopFrame.pack(fill=BOTH, expand=1)
     #CLOSE Label
     innerBottomLeftFrame = Frame(self, background="black")
     innerBottomLeftFrame.place(x=0, width=self.wRoot/2, 
         y=self.hRoot-200, height=200)
     closeLabel = Label(innerBottomLeftFrame, bg="black", fg="black",
         text="CLOSE", font=("Comic Sans MS", 48, "bold"))
     innerBottomLeftFrame.bind("<Enter>", lambda f: closeLabel.config(fg="white"))
     innerBottomLeftFrame.bind("<Leave>", lambda f: closeLabel.config(fg="black"))
     innerBottomLeftFrame.bind("<Button-1>", lambda f: self.root.quit())
     closeLabel.bind("<Button-1>", lambda f: self.root.quit())
     closeLabel.pack(fill=BOTH)
     #SHUT DOWN Label
     innerBottomRightFrame = Frame(self, background="black")
     innerBottomRightFrame.place(x=self.wRoot/2, width=self.wRoot/2, 
         y=self.hRoot-200, height=200)
     shutdownLabel = Label(innerBottomRightFrame, bg="black", fg="black",
         text="SHUT DOWN", font=("Comic Sans MS", 48, "bold"))
     innerBottomRightFrame.bind("<Enter>", lambda f: shutdownLabel.config(fg="white"))
     innerBottomRightFrame.bind("<Leave>", lambda f: shutdownLabel.config(fg="black"))
     innerBottomRightFrame.bind("<Button-1>", self.shutdown)
     shutdownLabel.bind("<Button-1>", self.shutdown)
     shutdownLabel.pack(fill=BOTH)
     #design the FullScreenApp
     self.pack(fill=BOTH, expand=1)