예제 #1
0
    def test_widget_destroy(self):
        # automatically created variable
        x = ttk.LabeledScale(self.root)
        var = x._variable._name
        x.destroy()
        self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)

        # manually created variable
        myvar = tkinter.DoubleVar(self.root)
        name = myvar._name
        x = ttk.LabeledScale(self.root, variable=myvar)
        x.destroy()
        if self.wantobjects:
            self.assertEqual(x.tk.globalgetvar(name), myvar.get())
        else:
            self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
        del myvar
        self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)

        # checking that the tracing callback is properly removed
        myvar = tkinter.IntVar(self.root)
        # LabeledScale will start tracing myvar
        x = ttk.LabeledScale(self.root, variable=myvar)
        x.destroy()
        # Unless the tracing callback was removed, creating a new
        # LabeledScale with the same var will cause an error now. This
        # happens because the variable will be set to (possibly) a new
        # value which causes the tracing callback to be called and then
        # it tries calling instance attributes not yet defined.
        ttk.LabeledScale(self.root, variable=myvar)
        if hasattr(sys, 'last_type'):
            self.assertNotEqual(sys.last_type, tkinter.TclError)
예제 #2
0
    def test_initialization(self):
        # master passing
        master = tkinter.Frame(self.root)
        x = ttk.LabeledScale(master)
        self.assertEqual(x.master, master)
        x.destroy()

        # variable initialization/passing
        passed_expected = (('0', 0), (0, 0), (10, 10), (-1, -1),
                           (sys.maxsize + 1, sys.maxsize + 1))
        if self.wantobjects:
            passed_expected += ((2.5, 2), )
        for pair in passed_expected:
            x = ttk.LabeledScale(self.root, from_=pair[0])
            self.assertEqual(x.value, pair[1])
            x.destroy()
        x = ttk.LabeledScale(self.root, from_='2.5')
        self.assertRaises(ValueError, x._variable.get)
        x.destroy()
        x = ttk.LabeledScale(self.root, from_=None)
        self.assertRaises(ValueError, x._variable.get)
        x.destroy()
        # variable should have its default value set to the from_ value
        myvar = tkinter.DoubleVar(self.root, value=20)
        x = ttk.LabeledScale(self.root, variable=myvar)
        self.assertEqual(x.value, 0)
        x.destroy()
        # check that it is really using a DoubleVar
        x = ttk.LabeledScale(self.root, variable=myvar, from_=0.5)
        self.assertEqual(x.value, 0.5)
        self.assertEqual(x._variable._name, myvar._name)
        x.destroy()

        # widget positionment
        def check_positions(scale, scale_pos, label, label_pos):
            self.assertEqual(scale.pack_info()['side'], scale_pos)
            self.assertEqual(label.place_info()['anchor'], label_pos)

        x = ttk.LabeledScale(self.root, compound='top')
        check_positions(x.scale, 'bottom', x.label, 'n')
        x.destroy()
        x = ttk.LabeledScale(self.root, compound='bottom')
        check_positions(x.scale, 'top', x.label, 's')
        x.destroy()
        # invert default positions
        x = ttk.LabeledScale(self.root, compound='unknown')
        check_positions(x.scale, 'top', x.label, 's')
        x.destroy()
        x = ttk.LabeledScale(self.root)  # take default positions
        check_positions(x.scale, 'bottom', x.label, 'n')
        x.destroy()

        # extra, and invalid, kwargs
        self.assertRaises(tkinter.TclError, ttk.LabeledScale, master, a='b')
예제 #3
0
 def test_variable_change(self):
     x = ttk.LabeledScale(self.root)
     x.pack()
     x.wait_visibility()
     x.update()
     curr_xcoord = x.scale.coords()[0]
     newval = x.value + 1
     x.value = newval
     x.update()
     self.assertEqual(x.value, newval)
     self.assertEqual(x.label['text'],
                      newval if self.wantobjects else str(newval))
     self.assertEqual(float(x.scale.get()), newval)
     self.assertGreater(x.scale.coords()[0], curr_xcoord)
     self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x']))
     if self.wantobjects:
         conv = lambda x: x
     else:
         conv = int
     x.value = conv(x.scale['to']) + 1
     x.update()
     self.assertEqual(x.value, newval)
     self.assertEqual(conv(x.label['text']), newval)
     self.assertEqual(float(x.scale.get()), newval)
     self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x']))
     x.value = newval = newval + 1.5
     x.update()
     self.assertEqual(x.value, int(newval))
     self.assertEqual(conv(x.label['text']), int(newval))
     self.assertEqual(float(x.scale.get()), newval)
     x.destroy()
예제 #4
0
def setup_gui(root_window, mqttclient):
    """ Constructs and sets up widgets on the given window. """
    frame = ttk.Frame(root_window, padding=30)
    frame.grid()
    label1 = ttk.Label(frame, text='Enter the play you want the robot to call')
    label1.grid(row=4, column=0)
    widget = ttk.Label(frame, text='ROBO-FOOTBALL 2018', font=80)
    widget.grid(row=0, column=1)
    new_thing = ttk.LabeledScale(frame, from_=0, to=100)
    new_thing.grid(row=5, column=2)
    label2 = ttk.Label(frame, text='Enter the starting speed', width=30)
    label2.grid(row=4, column=2)
    play_entry_box = ttk.Entry(frame)
    call_play_button = ttk.Button(frame, text="Call Play", width=20)
    turn_right_button = ttk.Button(frame, text="Turn Right", width=15)
    turn_left_button = ttk.Button(frame, text="Turn Left", width=15)
    turn_left_button.grid(row=7, column=0)
    turn_right_button.grid(row=7, column=2)
    play_entry_box.grid(row=5, column=0)
    call_play_button.grid(row=6, column=1)

    call_play_button['command'] = \
        lambda: handle_call_play(play_entry_box, new_thing, mqttclient)

    turn_right_button['command'] = \
        lambda: handle_turn_right(mqttclient)

    turn_left_button['command'] = \
        lambda: handle_turn_left(mqttclient)
예제 #5
0
    def test_horizontal_range(self):
        lscale = ttk.LabeledScale(self.root, from_=0, to=10)
        lscale.pack()
        lscale.wait_visibility()
        lscale.update()

        linfo_1 = lscale.label.place_info()
        prev_xcoord = lscale.scale.coords()[0]
        self.assertEqual(prev_xcoord, int(linfo_1['x']))
        # change range to: from -5 to 5. This should change the x coord of
        # the scale widget, since 0 is at the middle of the new
        # range.
        lscale.scale.configure(from_=-5, to=5)
        # The following update is needed since the test doesn't use mainloop,
        # at the same time this shouldn't affect test outcome
        lscale.update()
        curr_xcoord = lscale.scale.coords()[0]
        self.assertNotEqual(prev_xcoord, curr_xcoord)
        # the label widget should have been repositioned too
        linfo_2 = lscale.label.place_info()
        self.assertEqual(lscale.label['text'], 0 if self.wantobjects else '0')
        self.assertEqual(curr_xcoord, int(linfo_2['x']))
        # change the range back
        lscale.scale.configure(from_=0, to=10)
        self.assertNotEqual(prev_xcoord, curr_xcoord)
        self.assertEqual(prev_xcoord, int(linfo_1['x']))

        lscale.destroy()
예제 #6
0
    def test_variable_change(self):
        x = ttk.LabeledScale(self.root)
        x.pack()
        x.wait_visibility()
        x.update()

        curr_xcoord = x.scale.coords()[0]
        newval = x.value + 1
        x.value = newval
        # The following update is needed since the test doesn't use mainloop,
        # at the same time this shouldn't affect test outcome
        x.update()
        self.assertEqual(x.label['text'],
                         newval if self.wantobjects else str(newval))
        self.assertGreater(x.scale.coords()[0], curr_xcoord)
        self.assertEqual(x.scale.coords()[0],
            int(x.label.place_info()['x']))

        # value outside range
        if self.wantobjects:
            conv = lambda x: x
        else:
            conv = int
        x.value = conv(x.scale['to']) + 1 # no changes shouldn't happen
        x.update()
        self.assertEqual(conv(x.label['text']), newval)
        self.assertEqual(x.scale.coords()[0],
            int(x.label.place_info()['x']))

        x.destroy()
예제 #7
0
    def initWidgets(self):
        self.scale = ttk.LabeledScale(self.master,
            from_ = -100,  # 设置最大值
            to = 100,  # 设置最小值
#            compound = BOTTOM # 设置显示数值的Label在下方
        )
        self.scale.value = -20
        self.scale.pack(fill=X, expand=YES)
예제 #8
0
 def test_initialization_no_master(self):
     # no master passing
     with swap_attr(tkinter, '_default_root', None), \
          swap_attr(tkinter, '_support_default_root', True):
         try:
             x = ttk.LabeledScale()
             self.assertIsNotNone(tkinter._default_root)
             self.assertEqual(x.master, tkinter._default_root)
             self.assertEqual(x.tk, tkinter._default_root.tk)
             x.destroy()
         finally:
             destroy_default_root()
예제 #9
0
 def test_widget_destroy(self):
     x = ttk.LabeledScale(self.root)
     var = x._variable._name
     x.destroy()
     self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
     myvar = tkinter.DoubleVar(self.root)
     name = myvar._name
     x = ttk.LabeledScale(self.root, variable=myvar)
     x.destroy()
     if self.wantobjects:
         self.assertEqual(x.tk.globalgetvar(name), myvar.get())
     else:
         self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
     del myvar
     self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
     myvar = tkinter.IntVar(self.root)
     x = ttk.LabeledScale(self.root, variable=myvar)
     x.destroy()
     ttk.LabeledScale(self.root, variable=myvar)
     if hasattr(sys, 'last_type'):
         self.assertNotEqual(sys.last_type, tkinter.TclError)
예제 #10
0
 def create_score_entry(self):
     ttk.Label(self.search_options_frame, text='Minimum Score Match:').grid(
         column=0,
         row=2,
         sticky=E)
     self.score = IntVar(value=90)
     self.score_entry = ttk.LabeledScale(self.search_options_frame,
                                         variable=self.score, from_=100,
                                         to=0)
     self.score_entry.scale.set(90)
     self.score_entry.grid(column=1, row=2, sticky=(W, E), columnspan=2)
     self.score_entry.label.update()
예제 #11
0
 def test_resize(self):
     x = ttk.LabeledScale(self.root)
     x.pack(expand=True, fill='both')
     x.wait_visibility()
     x.update()
     width, height = x.master.winfo_width(), x.master.winfo_height()
     width_new, height_new = width * 2, height * 2
     x.value = 3
     x.update()
     x.master.wm_geometry('%dx%d' % (width_new, height_new))
     self.assertEqual(int(x.label.place_info()['x']), x.scale.coords()[0])
     x.master.wm_geometry('%dx%d' % (width, height))
     x.destroy()
예제 #12
0
    def test_initialization(self):
        master = tkinter.Frame(self.root)
        x = ttk.LabeledScale(master)
        self.assertEqual(x.master, master)
        x.destroy()
        passed_expected = ('0',
                           0), (0, 0), (10, 10), (-1, -1), (sys.maxsize + 1,
                                                            sys.maxsize +
                                                            1), (2.5,
                                                                 2), ('2.5', 2)
        for pair in passed_expected:
            x = ttk.LabeledScale(self.root, from_=pair[0])
            self.assertEqual(x.value, pair[1])
            x.destroy()
        x = ttk.LabeledScale(self.root, from_=None)
        self.assertRaises((ValueError, tkinter.TclError), x._variable.get)
        x.destroy()
        myvar = tkinter.DoubleVar(self.root, value=20)
        x = ttk.LabeledScale(self.root, variable=myvar)
        self.assertEqual(x.value, 0)
        x.destroy()
        x = ttk.LabeledScale(self.root, variable=myvar, from_=0.5)
        self.assertEqual(x.value, 0.5)
        self.assertEqual(x._variable._name, myvar._name)
        x.destroy()

        def check_positions(scale, scale_pos, label, label_pos):
            self.assertEqual(scale.pack_info()['side'], scale_pos)
            self.assertEqual(label.place_info()['anchor'], label_pos)

        x = ttk.LabeledScale(self.root, compound='top')
        check_positions(x.scale, 'bottom', x.label, 'n')
        x.destroy()
        x = ttk.LabeledScale(self.root, compound='bottom')
        check_positions(x.scale, 'top', x.label, 's')
        x.destroy()
        x = ttk.LabeledScale(self.root, compound='unknown')
        check_positions(x.scale, 'top', x.label, 's')
        x.destroy()
        x = ttk.LabeledScale(self.root)
        check_positions(x.scale, 'bottom', x.label, 'n')
        x.destroy()
        self.assertRaises(tkinter.TclError, ttk.LabeledScale, master, a='b')
    def test_resize(self):
        x = ttk.LabeledScale(self.root)
        x.pack(expand=True, fill='both')
        gc_collect()  # For PyPy or other GCs.
        x.update()

        width, height = x.master.winfo_width(), x.master.winfo_height()
        width_new, height_new = width * 2, height * 2

        x.value = 3
        x.update()
        x.master.wm_geometry("%dx%d" % (width_new, height_new))
        self.assertEqual(int(x.label.place_info()['x']), x.scale.coords()[0])

        # Reset geometry
        x.master.wm_geometry("%dx%d" % (width, height))
        x.destroy()
예제 #14
0
파일: Book_gui.py 프로젝트: sprotg/2020_3d
    def rediger_bog(self):
        def change_book():
            b.titel = en_titel.get()
            b.forfatter = en_forfatter.get()
            self.data.update_book(b)
            b.give_rating(sc_rating.scale.get())
            self.opdater_tabel()
            dlg.destroy()
            dlg.update()

        def close():
            dlg.destroy()
            dlg.update()

        curItem = self.db_view.item(self.db_view.focus())['values']

        if len(curItem) > 0:
            b = self.data.get_book(curItem[4])

            dlg = tk.Toplevel()

            lbl_titel = ttk.Label(dlg, text='Titel')
            lbl_titel.grid(column =0, row = 0)
            en_titel = ttk.Entry(dlg)
            en_titel.grid(column=1, row=0)
            en_titel.delete(0, tk.END)
            en_titel.insert(0, b.titel)

            lbl_forfatter = ttk.Label(dlg, text='Forfatter')
            lbl_forfatter.grid(column =0, row = 1)
            en_forfatter = ttk.Entry(dlg)
            en_forfatter.grid(column=1, row=1)
            en_forfatter.delete(0, tk.END)
            en_forfatter.insert(0, b.forfatter)

            lbl_rating = ttk.Label(dlg, text='Rating')
            lbl_rating.grid(column =0, row = 2)
            sc_rating = ttk.LabeledScale(dlg, from_ = 0, to = 5)
            sc_rating.value = b.get_rating()
            sc_rating.grid(column=1, row=2)

            but_annuller = ttk.Button(dlg, text="Annuller", command=close)
            but_annuller.grid(column=1,row=3)
            but_ok = ttk.Button(dlg, text="Gem ændringer", command=change_book)
            but_ok.grid(column=0,row=3)
예제 #15
0
 def test_horizontal_range(self):
     lscale = ttk.LabeledScale(self.root, from_=0, to=10)
     lscale.pack()
     lscale.wait_visibility()
     lscale.update()
     linfo_1 = lscale.label.place_info()
     prev_xcoord = lscale.scale.coords()[0]
     self.assertEqual(prev_xcoord, int(linfo_1['x']))
     lscale.scale.configure(from_=-5, to=5)
     lscale.update()
     curr_xcoord = lscale.scale.coords()[0]
     self.assertNotEqual(prev_xcoord, curr_xcoord)
     linfo_2 = lscale.label.place_info()
     self.assertEqual(lscale.label['text'], 0 if self.wantobjects else '0')
     self.assertEqual(curr_xcoord, int(linfo_2['x']))
     lscale.scale.configure(from_=0, to=10)
     self.assertNotEqual(prev_xcoord, curr_xcoord)
     self.assertEqual(prev_xcoord, int(linfo_1['x']))
     lscale.destroy()
def setup_gui(root_window, mqtt_client):
    """ Constructs and sets up widgets on the given window. """
    frame = ttk.Frame(root_window, padding=30)
    frame.grid()
    label1 = ttk.Label(frame, text='Mario', font=100)
    go_forward_button = ttk.Button(frame, text="Go forward", width=20)
    stop_button = ttk.Button(frame, text="stop", width=20)
    mario = ttk.Button(frame, text="It's a me, Mario!", width=20)
    label2 = ttk.Label(frame, text='Adjust starting speed:')
    speed_adjuster = ttk.LabeledScale(frame, from_=0, to=100)

    go_forward_button.grid(row=2, column=0)
    stop_button.grid(row=2, column=1)
    mario.grid(row=2, column=2)
    label1.grid(row=0, column=1)
    label2.grid(row=1, column=0)
    speed_adjuster.grid(row=3, column=0)
    go_forward_button['command'] = \
        lambda: handle_go_forward(mqtt_client, speed_adjuster)

    stop_button['command'] = lambda: handle_stop(mqtt_client)
def uj_tev(*_):
    global tev_lista

    tev_ablak = tkinter.Frame(ablak)

    megn_szoveg = ttk.Label(tev_ablak, text="Megnevezés:")
    megn_szoveg.pack(side=tkinter.LEFT, padx=10, pady=20)

    megn_mezo = ttk.Entry(tev_ablak)
    megn_mezo.pack(side=tkinter.LEFT, padx=10, pady=20)
    megn_mezo.bind("<FocusIn>", uj_tev)
    megn_mezo.bind("<KeyRelease>", kiegeszit)

    i = len(tev_lista)
    csuszka = ttk.LabeledScale(tev_ablak, to=100)
    csuszka.pack(padx=10)
    csuszka.scale.bind("<ButtonRelease>", lambda x: osszeg_100(i, x))

    if tev_lista:
        tev_lista[-1].winfo_children()[1].unbind("<FocusIn>")
        tev_lista[-1].winfo_children()[0].unbind("<ButtonRelease>")
    tev_lista.append(tev_ablak)
    tev_ablak.pack()
예제 #18
0
    def test_variable_change(self):
        x = ttk.LabeledScale()
        x.pack()
        x.wait_visibility()
        x.update()

        curr_xcoord = x.scale.coords()[0]
        newval = x.value + 1
        x.value = newval
        # The following update is needed since the test doesn't use mainloop,
        # at the same time this shouldn't affect test outcome
        x.update()
        self.assertEqual(x.label['text'], newval)
        self.assertTrue(x.scale.coords()[0] > curr_xcoord)
        self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x']))

        # value outside range
        x.value = x.scale['to'] + 1  # no changes shouldn't happen
        x.update()
        self.assertEqual(x.label['text'], newval)
        self.assertEqual(x.scale.coords()[0], int(x.label.place_info()['x']))

        x.destroy()
예제 #19
0
import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

ttk.Button(text='ttk').pack()

tk.Button(text='tk', fg="red").pack()

ttk.Label(text="ttk").pack()

tk.Label(text="tk").pack()

tk.Scale().pack()

ttk.Scale().pack()

ttk.LabeledScale().pack()

tk.Spinbox().pack()

ttk.Spinbox().pack()

ttk.Menubutton().pack()

root.mainloop()
예제 #20
0
# …………………………

F1 = ttk.Frame(window, style='Frame1.TFrame', height=100, width=100).pack()

# 标签框是一个简单的容器小部件。它的主要目的是充当复杂窗口布局的间隔物或容器
lfr = ttk.Labelframe(window, text='This is a A').pack(fill=BOTH, expand=True)
ttk.Label(lfr, text='Inside the LabelFrame').pack()
# x
bt = ttk.Button(window, text="Quit", command=window.destroy).pack()
mt = ttk.Menubutton(window, text='Menu').pack()
lt = ttk.Label(window, text='Doc').pack()
ttk.Entry(window).pack()
ttk.Checkbutton(window).pack()
ttk.Combobox(window).pack()
ttk.LabeledScale(window).pack()
ttk.Radiobutton(window).pack()
ttk.Progressbar(window).pack()
ttk.Scrollbar(window).pack()
ttk.Scale(window).pack()
#
ttk.Sizegrip(window).pack()
ttk.Spinbox(window).pack()
#
m1 = ttk.Panedwindow(window)
m1.pack(fill=BOTH, expand=1)
left = ttk.Label(m1, text='one')
m1.add(left)
#
"""插入列"""
tree = ttk.Treeview(window)
예제 #21
0
    def __init__(self, playlists: list[Playlist], defaults: dict):

        root = ThemedTk(theme='black')
        root.option_add('*tearOff', tk.FALSE)
        root.wm_title("btecify")
        root.wm_iconbitmap('assets\\btecify.ico')
        root.resizable(width=False, height=False)
        root.wm_iconify()
        root.wm_deiconify()

        for namefont in tkfont.names(root):
            rootfont = tkfont.nametofont(namefont)
            rootfont.config(family="Lucida Console")

        def _onclose():
            self.output = ["EXIT"]
            root.destroy()

        root.protocol("WM_DELETE_WINDOW", _onclose)

        self.selectedplaylist = tk.StringVar()
        self.playlists = playlists
        self._generateplaylistnames()
        self.songqueuevar = tk.StringVar(value=[])
        self.volume = tk.IntVar(value=50)
        self.seek = tk.DoubleVar(value=0)
        self.songlistvar = tk.StringVar(value=[])
        self.playlistsongsvar = tk.StringVar(value=[])
        self.progressbarvar = tk.IntVar(value=0)
        self.songsearchqueryvar = tk.StringVar(value="")
        self.extrainfoplaylistsvar = tk.StringVar(value=[])
        self.searchfunc = searchsongname
        self.discordpresencevar = tk.BooleanVar(value=defaults['discord'])

        self.keybinds: list[tuple[str, str]] = []

        # CONSOLE
        consolewindow = tk.Toplevel(root)
        consolewindow.wm_title("Console Logs")
        consolewindow.wm_protocol("WM_DELETE_WINDOW",
                                  lambda: consolewindow.wm_withdraw())
        consolewindow.wm_withdraw()
        consolewindow.wm_resizable(False, False)

        consolewindowframe = ttk.Frame(consolewindow,
                                       padding=5,
                                       relief="groove")
        consolewindowframe.grid()

        consolewindowtext = tk.Text(consolewindowframe,
                                    foreground='white',
                                    background='black',
                                    state='disabled',
                                    width=100,
                                    height=40)
        consolewindowtext.grid(row=0, column=0)

        consolewindowtextscrollbar = ttk.Scrollbar(
            consolewindowframe,
            orient=tk.VERTICAL,
            command=consolewindowtext.yview)
        consolewindowtext['yscrollcommand'] = consolewindowtextscrollbar.set
        consolewindowtextscrollbar.grid(row=0, column=1, sticky='ns')

        def resetconsolewindow(*args):
            consolewindowtext.yview_moveto(1.0)

        consolewindowtext.bind('<Visibility>', resetconsolewindow)
        consolewindowtext.bind('<FocusIn>', resetconsolewindow)

        # KEYBINDS
        keybindwindow = tk.Toplevel(root)
        keybindwindow.wm_title("Keybindings")
        keybindwindow.wm_protocol("WM_DELETE_WINDOW",
                                  lambda: keybindwindow.wm_withdraw())
        keybindwindow.wm_resizable(False, False)
        keybindwindow.wm_withdraw()

        keybindwindowframe = ttk.Frame(keybindwindow,
                                       padding=5,
                                       relief='groove')
        keybindwindowframe.grid()

        keybindlistframe = ttk.Frame(keybindwindowframe,
                                     padding=3,
                                     relief='groove')
        keybindlistframe.grid(row=0, column=0)

        keybindings = [i for i in defaults['keybinds']]
        keybindlist = []
        for x in range(len(keybindings)):
            kbname = str(keybindings[x])
            newframe = ttk.Frame(keybindlistframe)
            newframe.grid(column=0, row=x)

            newlabel = ttk.Label(
                newframe,
                text=kbname + ": ",
                width=max(map(lambda a: len(a), keybindings)) + 2)
            newlabel.grid(row=0, column=0)

            keybindtextvariable = tk.StringVar("")
            newentry = ttk.Entry(newframe, textvariable=keybindtextvariable)
            newentry.grid(row=0, column=1)
            newentry.bind('<FocusIn>',
                          lambda *args: self._addchange('keybinds'))

            keybindlist.append((kbname, keybindtextvariable))

        keybindbuttonsframe = ttk.Frame(keybindwindowframe,
                                        padding=3,
                                        relief='groove')
        keybindbuttonsframe.grid(row=1, column=0)

        keybindbuttondefault = ttk.Button(
            keybindbuttonsframe,
            text="RESET TO DEFAULTS",
            command=lambda: self._setoutput("defaultkeybinds"))
        keybindbuttondefault.grid(row=0, column=0)

        keybindbuttonconfirm = ttk.Button(
            keybindbuttonsframe,
            text="CONFIRM KEYBINDINGS",
            command=lambda: self._setoutput(
                "updatekeybinds", [(i[0], i[1].get()) for i in keybindlist]))
        keybindbuttonconfirm.grid(row=0, column=1)

        # MENU
        menubar = tk.Menu(root)
        root.configure(menu=menubar)

        menuplaylist = tk.Menu(menubar)
        menusong = tk.Menu(menubar)
        menufile = tk.Menu(menubar)

        menubar.add_cascade(menu=menuplaylist, label="Playlist")
        menubar.add_cascade(menu=menusong, label="Song")
        menubar.add_cascade(menu=menufile, label="File")

        menubar.add_separator()

        menubar.add_command(label="Playlist: None", state="disabled")
        menubarplaylistlabelindex = len(menubar.winfo_children()) + 1

        menuplaylist.add_command(label="New...", command=self._newplaylist)
        menuplaylist.add_command(label="Delete", command=self._deleteplaylist)
        menuplaylist.add_command(label="Rename...",
                                 command=self._renameplaylist)
        menuplaylist.add_command(label="Copy...", command=self._copyplaylist)
        menuplaylist.add_separator()
        menuplaylist.add_command(label="Reset watched",
                                 command=self._unwatchplaylist)
        menuplaylist.add_command(label="Requeue", command=self._requeue)
        menuplaylist.add_separator()
        menuplaylist.add_command(label="Reset from Youtube",
                                 command=self._resetfromyoutube)

        menusong.add_command(label="New...", command=self._newsong)
        menusong.add_command(label="Delete",
                             command=lambda: self._setoutput(
                                 "deletesongs", *self._getselectedsongs()))
        menusong.add_separator()
        menusong.add_command(label="Add selected songs to selected playlist",
                             command=self._addsongtoplaylist)
        menusong.add_command(
            label="Remove selected songs from selected playlist",
            command=lambda: self._setoutput("removesongsfromplaylist",
                                            self._getselectedplaylist(),
                                            self._getselectedsongs()))
        menusong.add_separator()
        menusong.add_command(label="Play selected song",
                             command=self._playselectedsong)
        menusong.add_command(label="Play random song",
                             command=lambda: self._setoutput("randomsong"))

        menufile.add_command(label="View console logs...",
                             command=consolewindow.wm_deiconify)
        menufile.add_command(
            label="Open data directory...",
            command=lambda: self._setoutput("opendatadirectory"))
        menufile.add_separator()
        menufile.add_command(label="Change keybinds...",
                             command=keybindwindow.wm_deiconify)
        menufile.add_separator()
        menufile.add_checkbutton(
            label="Discord Presence",
            command=lambda: self._setoutput('discordpresence',
                                            self.discordpresencevar.get()),
            variable=self.discordpresencevar)
        menufile.add_separator()
        menufile.add_command(label="Change API key...",
                             command=lambda: self._setoutput("newapikey"))
        menufile.add_separator()
        menufile.add_command(label="Login Details...",
                             command=self._logindetails)
        menufile.add_command(label="Sync playlist to btecify servers",
                             command=lambda: self._setoutput("syncwithserver"))

        # PRIMARY FRAME

        primaryframe = ttk.Frame(root)
        primaryframe.grid()

        # QUEUE
        queuelabelframe = ttk.Labelframe(primaryframe,
                                         text="Song queue",
                                         relief='groove',
                                         borderwidth=5)
        queuelabelframe.grid(column=0,
                             row=0,
                             columnspan=2,
                             rowspan=2,
                             sticky='nswe')

        queuelist = mylistbox(queuelabelframe,
                              height=15,
                              listvariable=self.songqueuevar,
                              width=50,
                              exportselection=False,
                              selectmode=tk.MULTIPLE)
        queuelistscrollbar = ttk.Scrollbar(queuelabelframe,
                                           orient=tk.VERTICAL,
                                           command=queuelist.yview)

        queuelist.grid(column=0, row=0, sticky='nswe')
        queuelistscrollbar.grid(column=1, row=0, sticky='ns')

        queuelist['yscrollcommand'] = queuelistscrollbar.set

        # PLAYER INFORMATION
        playingframe = ttk.Labelframe(primaryframe,
                                      text="Playing Song",
                                      relief='groove',
                                      padding=5)
        playingframe.grid(column=2, row=0, sticky='new')

        songinfo = ttk.Label(
            playingframe,
            text=
            f"No playlist\nNo song playing\nNo song author\nNo duration\n{PLAYINGINFOPLACEHOLDER}",
            justify=tk.CENTER,
            anchor=tk.CENTER)
        songinfo.grid(column=0, row=0, sticky='ew')

        songdesc = ttk.Label(playingframe,
                             text="",
                             justify=tk.CENTER,
                             anchor=tk.CENTER)
        songdesc.grid(column=0, row=1)

        songprogress = ttk.Progressbar(playingframe,
                                       orient=tk.HORIZONTAL,
                                       mode='determinate',
                                       variable=self.progressbarvar)
        songprogress.grid(column=0, row=3, sticky='wes')

        songseeker = ttk.Scale(playingframe, from_=0, to=1, variable=self.seek)
        songseeker.grid(column=0, row=4, sticky='wes')
        songseeker.bind("<ButtonPress-1>",
                        lambda *args: self.changes.update({'seeking': True}))
        songseeker.bind("<ButtonRelease-1>",
                        lambda *args: self.changes.update({'seeking': False}))

        playingframe.grid_rowconfigure((0, 1, 2, 3), weight=1)

        # SONG SELECTION AND SONG VIEWING
        songselectionandviewingframe = ttk.Frame(primaryframe)
        songselectionandviewingframe.grid(column=3,
                                          row=0,
                                          columnspan=2,
                                          rowspan=2)

        songlistnotebook = ttk.Notebook(songselectionandviewingframe)
        songlistnotebook.grid(column=0, row=0)

        songlistframe = ttk.Frame(songlistnotebook, padding=1)

        songlist = mylistbox(songlistframe,
                             height=15,
                             listvariable=self.songlistvar,
                             selectmode=tk.MULTIPLE,
                             bg="#282828",
                             disabledforeground="gray80",
                             fg="white",
                             activestyle='dotbox',
                             selectbackground="#282828",
                             selectforeground="red2",
                             width=50,
                             exportselection=False)
        songlistscrollbar = ttk.Scrollbar(songlistframe,
                                          orient=tk.VERTICAL,
                                          command=songlist.yview)
        ################################################################################################################

        playlistsongsframe = ttk.Frame(songlistnotebook, padding=1)

        playlistsongslist = mylistbox(playlistsongsframe,
                                      height=15,
                                      listvariable=self.playlistsongsvar,
                                      selectmode=tk.MULTIPLE,
                                      bg="#282828",
                                      disabledforeground="gray80",
                                      fg="white",
                                      activestyle='dotbox',
                                      selectbackground="#282828",
                                      selectforeground="red2",
                                      width=50,
                                      exportselection=False)
        playlistsongslistscrollbar = ttk.Scrollbar(
            playlistsongsframe,
            orient=tk.VERTICAL,
            command=playlistsongslist.yview)
        ################################################################################################################

        _songlistsearchchangedcommand = root._register(
            self._songlistsearchchanged)
        songsearchentry = ttk.Entry(
            songselectionandviewingframe,
            validate="all",
            validatecommand=(_songlistsearchchangedcommand, '%V'),
            textvariable=self.songsearchqueryvar,
        )

        self.completeselectedsongs: list[Song] = []

        resetsonglistselectionbutton = ttk.Button(
            songselectionandviewingframe,
            text="RESET SELECTION|SELECTED: 0",
            command=lambda: self._addchange("resetselectedsongs"))

        songlist.grid(row=0, column=0, columnspan=2)
        songlistscrollbar.grid(row=0, column=2, sticky='wns')

        playlistsongslist.grid(row=0, column=0, columnspan=2)
        playlistsongslistscrollbar.grid(row=0, column=2, sticky='wns')

        songsearchentry.grid(row=1, column=0, sticky='ews')
        resetsonglistselectionbutton.grid(row=2, column=0, sticky='nw')

        songlist['yscrollcommand'] = songlistscrollbar.set
        playlistsongslist['yscrollcommand'] = playlistsongslistscrollbar.set

        songlistnotebook.add(songlistframe, text="Song list")
        songlistnotebook.add(playlistsongsframe, text="empty")

        # BOTTOM LEFT LOGO
        btecifyiconimage = tk.PhotoImage(file="assets/btecify64.png")
        btecifyiconlabel = ttk.Label(primaryframe, image=btecifyiconimage)
        btecifyiconlabel.grid(column=0, row=2, sticky='ws')

        # PLAYLIST SELECT
        playlistselectframe = ttk.LabelFrame(primaryframe,
                                             text="Playlist select",
                                             relief='groove',
                                             padding=3)
        playlistselectframe.grid(row=2, column=3, sticky='wn')

        playlistselectcombobox = ttk.Combobox(
            playlistselectframe,
            values=self.playlistnames,
            textvariable=self.selectedplaylist,
            width=26,
            state='readonly')
        self.selectedplaylist.trace_add(
            mode="write", callback=self._playlistcomboboxvalueupdated)
        playlistselectcombobox.set(playlists[0].name)
        playlistselectcombobox.grid(sticky='ewn')

        playlistselectbutton = ttk.Button(playlistselectframe,
                                          text="SWITCH TO PLAYLIST",
                                          command=self._chooseplaylist)
        playlistselectbutton.grid(row=1, sticky='s')

        # PLAYER BUTTONS
        bottommiddleframe = ttk.LabelFrame(primaryframe,
                                           text="Player controls",
                                           relief='groove',
                                           padding=5)
        bottommiddleframe.grid(column=2, row=1, sticky='wnse')

        pausebutton = ttk.Button(bottommiddleframe,
                                 text="PAUSE",
                                 command=self._pause)
        pausebutton.grid(row=0, column=0, columnspan=3, sticky='ew')

        skipbutton = ttk.Button(bottommiddleframe,
                                text="SKIP",
                                command=self._skip)
        skipbutton.grid(row=1, sticky='w')

        loopbutton = ttk.Button(bottommiddleframe,
                                text="LOOP: DISABLED",
                                command=lambda: self._setoutput("loop"))
        loopbutton.grid(row=1, column=1, padx=120)

        removesongbutton = ttk.Button(bottommiddleframe,
                                      text="REMOVE SONG",
                                      command=self._playerremovesongbutton)
        removesongbutton.grid(row=1, column=2, sticky='e')

        volumeslider = ttk.LabeledScale(bottommiddleframe,
                                        from_=0,
                                        to=100,
                                        variable=self.volume,
                                        compound='bottom')
        volumeslider.scale.set(defaults['volume'])
        volumeslider.scale.configure(command=self._volchange)
        volumeslider.label.update()
        volumeslider.grid(row=2, columnspan=3, sticky='ew')

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

        # EXTRA SONG INFORMATION
        extrasonginfoframe = ttk.Labelframe(primaryframe,
                                            text="Song Info",
                                            relief="sunken",
                                            padding=3)
        extrasonginfoframe.grid(row=2, column=1, columnspan=2, sticky="nesw")

        extrasonginfoname = ttk.Label(extrasonginfoframe,
                                      text="NO SONG",
                                      justify=tk.LEFT,
                                      anchor="w")
        extrasonginfoname.grid(row=0, column=0, sticky="nesw")

        extrasonginfoplaylistlabelframe = ttk.Labelframe(extrasonginfoframe,
                                                         text="In Playlists",
                                                         relief="groove",
                                                         padding=5)
        extrasonginfoplaylistlabelframe.grid(row=1, column=0, sticky="w")

        extrasonginfoplaylists = mylistbox(
            extrasonginfoplaylistlabelframe,
            height=5,
            selectmode="browse",
            listvariable=self.extrainfoplaylistsvar,
            exportselection=False)
        extrasonginfoplaylists.grid(row=0, column=0, sticky="")

        extrasonginfoplaylistsresetbutton = ttk.Button(
            extrasonginfoplaylistlabelframe,
            text="RESET",
            command=lambda: extrasonginfoplaylists.selection_clear(
                0, 100000) or self.extraplaylistselection.clear(
                ))  # Executes two statements in one lambda.

        extrasonginfoplaylistsresetbutton.grid(row=1, column=0, sticky='nesw')

        extrasonginfobuttonsframe = ttk.Frame(extrasonginfoplaylistlabelframe,
                                              padding=2)
        extrasonginfobuttonsframe.grid(row=0, column=1, sticky='nesw')

        extrasonginforemovebutton = ttk.Button(
            extrasonginfobuttonsframe,
            text="REMOVE SONG FROM PLAYLISTS",
            command=self._extrasonginforemovebuttonfunc)
        extrasonginforemovebutton.grid(row=0, column=0, sticky='')

        extrasonginfoopensong = ttk.Button(
            extrasonginfobuttonsframe,
            text="OPEN IN YOUTUBE",
            command=lambda: self._setoutput("openinyoutube", [
                *self.completeselectedsongs
            ] or [self._getselectedsong()]))
        extrasonginfoopensong.grid(row=1, column=0, sticky='')

        def _updatebasedonvalues():
            extrasongselectedplaylistvalues = self._getextrasongselectedplaylists(
                extrasonginfoplaylists)
            if self.changes[
                    'songinfo'] or extrasongselectedplaylistvalues != self.extraplaylistselection:
                if self.playingsong is not None:
                    self.progressbarvar.set(value=self.progressbar)
                    playlistofthissong = self.playlistwhichsongisfrom
                    if playlistofthissong is None:
                        playlistofthissong = "Played manually"
                        removesongbutton.configure(state='disabled')
                    else:
                        playlistofthissong = playlistofthissong.name
                        removesongbutton.configure(state='active')
                    songinfo['text'] = (
                        f"{playlistofthissong}\n{self.playingsong.name[:len(PLAYINGINFOPLACEHOLDER)]}\n{self.playingsong.author}\n{self.playingsong.duration}\n"
                        + PLAYINGINFOPLACEHOLDER)
                    if self.paused:
                        songdesc['text'] = "PAUSED"
                        pausebutton['text'] = "PLAY"
                    else:
                        songdesc['text'] = "PLAYING"
                        pausebutton['text'] = "PAUSE"

                if self.loop:
                    loopbutton['text'] = "LOOP: ENABLED"
                else:
                    loopbutton['text'] = "LOOP: DISABLED"

                targetsong = self._getselectedsong()
                if targetsong is not None:
                    extrasonginfoname['text'] = targetsong.name[:(
                        queuelist.cget("width") //
                        3) + len(PLAYINGINFOPLACEHOLDER)]
                    self.playlistswithtargetsong = list(
                        filter(lambda a: targetsong in a.getsongs(),
                               self.playlists))
                    self.extrainfoplaylistsvar.set(
                        [i.name for i in self.playlistswithtargetsong])
                    extrasonginfoplaylists.selection_clear(0, 1000000)
                    self.extraplaylistselection.extend([
                        i for i in extrasongselectedplaylistvalues
                        if i not in self.extraplaylistselection
                    ])

                    for i, v in enumerate(self.extraplaylistselection):
                        if v in self.playlistswithtargetsong:
                            extrasonginfoplaylists.selection_set(
                                self.playlistswithtargetsong.index(v))
                        else:
                            self.extraplaylistselection.remove(v)
                else:
                    extrasonginfoname['text'] = "NO SONG"
                    self.extrainfoplaylistsvar.set([])
                    extrasonginfoplaylists.selection_clear(0, 10000)

                self._addchange('songinfo', False)

            if self.changes['resetselectedsongs']:
                songlist.selection_clear(0, 100000000)
                queuelist.selection_clear(0, 100000)
                playlistsongslist.selection_clear(0, 100000)

                self.completeselectedsongs = []
                resetsonglistselectionbutton.configure(
                    text=f"RESET SELECTION   |   SELECTED: 0")
                self._addchange('songinfo')
                self._addchange('resetselectedsongs', False)

            currentlyselectedsonglistvalues = self._getselectedvalues(
                songlist, self.displaysonglist)
            currentlyselectedqueuevalues = self._getselectedvalues(
                queuelist, self.songqueue)
            currentlyselectedplaylistsongsvalues = self._getselectedvalues(
                playlistsongslist, self.displayplaylistsongs)
            displayablesongsinsonglist = set([
                i for i in self.displaysonglistnew
                if i in self.completeselectedsongs
            ])
            displayablesongsinqueuelist = set([
                i for i in self.songqueuenew if i in self.completeselectedsongs
            ])
            displayablesongsinplaylistsongslist = set([
                i for i in self.displayplaylistsongsnew
                if i in self.completeselectedsongs
            ])

            if self.changes['songlist'] or (
                    currentlyselectedsonglistvalues !=
                    displayablesongsinsonglist
            ) or (displayablesongsinqueuelist != currentlyselectedqueuevalues
                  ) or (displayablesongsinplaylistsongslist !=
                        currentlyselectedplaylistsongsvalues):
                if self.changes['songlist']:
                    self._songlistsearchchanged()
                    self.songlistvar.set(
                        value=[i.name for i in self.displaysonglistnew])
                    self.playlistsongsvar.set(
                        value=[i.name for i in self.displayplaylistsongsnew])
                    self.displaysonglist = self.displaysonglistnew
                    self.displayplaylistsongs = self.displayplaylistsongsnew

                    songlist.selection_clear(0, 1000000)
                    queuelist.selection_clear(0, 1000000)
                    playlistsongslist.selection_clear(0, 10000)

                    self._addchange('songinfo')
                    self._addchange('songlist', False)
                else:
                    self.completeselectedsongs.extend([
                        i for i in currentlyselectedsonglistvalues
                        if i not in self.completeselectedsongs
                    ])
                    self.completeselectedsongs.extend([
                        i for i in currentlyselectedqueuevalues
                        if i not in self.completeselectedsongs
                    ])
                    self.completeselectedsongs.extend([
                        i for i in currentlyselectedplaylistsongsvalues
                        if i not in self.completeselectedsongs
                    ])
                    for song in self.completeselectedsongs:
                        if song:
                            if song in self.displaysonglistnew:
                                songlist.selection_set(
                                    self.displaysonglistnew.index(song))
                            if song in self.songqueuenew:
                                queuelist.selection_set(
                                    self.songqueuenew.index(song))
                            if song in self.displayplaylistsongsnew:
                                playlistsongslist.selection_set(
                                    self.displayplaylistsongsnew.index(song))
                    self._addchange('songinfo')
                    resetsonglistselectionbutton.configure(
                        text=
                        f"RESET SELECTION   |   SELECTED: {len(self.completeselectedsongs)}"
                    )

            if self.changes['songqueue']:
                queuelist.selection_clear(0, 100000)
                self.songqueue = self.songqueuenew
                self.songqueuevar.set(value=[
                    f"{i+1:>3}: {v.name}" for i, v in enumerate(self.songqueue)
                ])
                self._addchange('songqueue', False)

            if self.changes['playlistoptions']:
                self._generateplaylistnames()
                playlistselectcombobox['values'] = self.playlistnames
                self._addchange('songinfo')
                self._addchange('playlistoptions', False)

            if self.changes['progressbar']:
                self.progressbarvar.set(value=self.progressbar)
                self._addchange('progressbar', False)

            if self.changes['playlistcomboboxupdate']:
                playlist = self._getselectedplaylist()
                label = "Playlist: "
                if playlist:
                    label += playlist.name
                else:
                    label += "None"
                menubar.entryconfigure(menubarplaylistlabelindex, label=label)

                songlistnotebook.tab(1, text=self._getselectedplaylist().name)
                self._addchange("songlist")
                self._addchange('playlistcomboboxupdate', False)

            if self.changes['updatelogs']:
                logstoadd = self.newlogs[len(self.logs):]
                consolewindowtext['state'] = 'normal'
                for log in logstoadd:
                    logstr = ""
                    timevalues = log[0]
                    logstr += f"{timevalues.tm_hour:0>2}:{timevalues.tm_min:0>2}:{timevalues.tm_sec:0>2}: "
                    for obj in log[1]:
                        objstring = str(obj).replace("\n", "\n\t  ")
                        logstr += objstring + " "
                    consolewindowtext.insert('end', logstr + "\n\n")
                consolewindowtext['state'] = 'disabled'

                self.logs = self.newlogs
                self._addchange('updatelogs', False)

            if self.changes['seeking']:
                val = self.seek.get()
                if 0 < val < 1:
                    self._setoutput('seek', self.seek.get())

            if self.changes['keybinds']:
                for kbset in keybindlist:
                    for j in self.keybinds:
                        if j[0] == kbset[0]:
                            kbset[1].set(j[1])
                self._addchange("keybinds", False)

            root.after(10, _updatebasedonvalues)

        _updatebasedonvalues()

        G.musicgui = self
        root.mainloop()
예제 #22
0
파일: Book_gui.py 프로젝트: sprotg/2020_3d
    def build_GUI(self):
        self.tabs = ttk.Notebook(self)
        bog_fane = ttk.Frame(self.tabs)
        sim_fane = ttk.Frame(self.tabs)

        self.tabs.add(bog_fane, text='Bøger')
        self.tabs.add(sim_fane, text='Simulering')

        right_frame = ttk.Frame(bog_fane)
        top_frame = ttk.Frame(right_frame)
        data_frame = ttk.Frame(right_frame)
        knap_frame = ttk.Frame(bog_fane)


        self.edit_button = ttk.Button(knap_frame, text="Rediger bog", command=self.rediger_bog)
        self.edit_button.pack(side=tk.TOP)

        self.del_button = ttk.Button(knap_frame, text="Slet bog", command=self.slet_bog)
        self.del_button.pack(side=tk.TOP)

        self.add_button = ttk.Button(knap_frame, text="Tilføj til kurv", command=self.tilfoj_kurv)
        self.add_button.pack(side=tk.TOP)

        self.buy_button = ttk.Button(knap_frame, text="Køb", command=self.koeb)
        self.buy_button.pack(side=tk.TOP)

        self.kurv_text = ScrolledText(knap_frame, state='disabled', width=20,height=5)
        self.kurv_text.pack(side=tk.TOP)
        self.kurv_text.configure(font='TkFixedFont')

        self.cons = ScrolledText(sim_fane, state='disabled', height=12)
        self.cons.pack(side = tk.TOP)
        self.cons.configure(font='TkFixedFont')
        self.after(1000, self.simulate_customer)

        butAnsaet = ttk.Button(sim_fane, text="Ansæt en person", command=self.ansaet)
        butAnsaet.pack(side=tk.TOP)
        butFyr = ttk.Button(sim_fane, text="Fyr en person", command=self.fyr)
        butFyr.pack(side=tk.TOP)
        self.after(3000, self.udbetal_loen)
        self.lblMoney = ttk.Label(sim_fane, text="Pengebeholdning: {}".format(self.data.money))
        self.lblMoney.pack(side=tk.TOP)
        self.lblAnsatte = ttk.Label(sim_fane, text="Antal ansatte: {}".format(len(self.data.ansatte)))
        self.lblAnsatte.pack(side=tk.TOP)
        self.sc_tilbud = ttk.LabeledScale (sim_fane,from_=50,to=110)
        self.sc_tilbud.pack(side=tk.TOP)

        self.db_view = ttk.Treeview(data_frame, column=("column1", "column2", "column3", "column4", "column5"), show='headings')
        self.db_view.bind("<ButtonRelease-1>", self.on_book_selected)
        self.db_view.heading("#1", text="Titel", command=self.sorterTitel)
        self.db_view.column("#1",minwidth=0,width=150, stretch=tk.NO)
        self.db_view.heading("#2", text="Forfatter", command=self.sorterForfatter)
        self.db_view.column("#2",minwidth=0,width=150, stretch=tk.NO)
        self.db_view.heading("#3", text="Årstal", command=self.sorterAarstal)
        self.db_view.column("#3",minwidth=0,width=80, stretch=tk.NO)
        self.db_view.heading("#4", text="Rating", command=self.sorterRating)
        self.db_view.column("#4",minwidth=0,width=80, stretch=tk.NO)
        self.db_view.heading("#5", text="id")
        #Læg mærke til at kolonne 5 ikke bliver vist.
        #Vi kan stadig finde id på den bog der er valgt,
        #men brugeren kan ikke se id.
        self.db_view["displaycolumns"]=("column1", "column2", "column3", "column4")
        ysb = ttk.Scrollbar(data_frame, command=self.db_view.yview, orient=tk.VERTICAL)
        self.db_view.configure(yscrollcommand=ysb.set)
        self.db_view.pack(side = tk.TOP, fill=tk.BOTH)

        self.trans_view = ttk.Treeview(knap_frame, column=("column1", "column2", "column3"), show='headings')
        self.trans_view.bind("<ButtonRelease-1>", self.on_trans_selected)
        self.trans_view.heading("#1", text="id")
        self.trans_view.column("#1",minwidth=0,width=20, stretch=tk.NO)
        self.trans_view.heading("#2", text="Pris")
        self.trans_view.column("#2",minwidth=0,width=30, stretch=tk.NO)
        self.trans_view.heading("#3", text="Status")
        self.trans_view.column("#3",minwidth=0,width=80, stretch=tk.NO)
        self.trans_view["displaycolumns"]=("column1", "column2", "column3")
        ysb = ttk.Scrollbar(data_frame, command=self.trans_view.yview, orient=tk.VERTICAL)
        self.trans_view.configure(yscrollcommand=ysb.set)
        self.trans_view.pack(side = tk.TOP, fill=tk.BOTH)

        #Top Frame
        self.can = tk.Canvas(top_frame, width=200, height=200)
        self.can.grid(column=1, row=0, rowspan=2)

        self.lbl_titel = ttk.Label(top_frame, text='Titel')
        self.lbl_forfatter = ttk.Label(top_frame, text='Forfatter')
        self.lbl_titel.grid(column=0, row=0)
        self.lbl_forfatter.grid(column=0, row=1)

        top_frame.pack(side=tk.TOP)
        data_frame.pack(side = tk.TOP)
        knap_frame.pack(side = tk.LEFT, fill=tk.Y)
        right_frame.pack(side=tk.RIGHT, fill=tk.Y)
        self.tabs.pack(expand=1, fill="both")

        self.pack()

        self.after(10000, self.udbetal_loen)
        self.after(1000, self.simulate_customer)
예제 #23
0
    pw_1, width=700,
    relief='raised'), ttk.Frame(pw_1, height=600,
                                relief='raised'), ttk.Frame(pw_2,
                                                            relief='raised')

pw.add(pw_1), pw.add(pw_2), pw_1.add(left_frame), pw_1.add(
    right_frame), pw_2.add(bottom_frame)

button, label, entry, radiobutton, checkbutton = ttk.Button(
    left_frame, text='按 钮', command=progressbar), ttk.Label(
        left_frame, text='标签'), ttk.Entry(left_frame), ttk.Radiobutton(
            left_frame, text='选项按钮'), ttk.Checkbutton(left_frame, text='复选框')

scale, labeledscale, spinbox = ttk.Scale(
    left_frame, from_=0, to=10, length=200,
    orient='horizontal'), ttk.LabeledScale(left_frame, from_=0,
                                           to=10), ttk.Spinbox(left_frame,
                                                               from_=0,
                                                               to=20,
                                                               increment=2)

labelframe = ttk.LabelFrame(left_frame, text='标签框架')
scrollbar = ttk.Scrollbar(labelframe)
listbox = tk.Listbox(labelframe,
                     height=6,
                     width=5,
                     yscrollcommand=scrollbar.set)
for i in range(20):
    listbox.insert('end', i)
scrollbar.config(command=listbox.yview)

stringvar1, stringvar2 = tk.StringVar(), tk.StringVar()
예제 #24
0
    def __init_params(self):
        tab_params = ttk.Frame(self.tab_control)
        self.tab_control.add(tab_params, text="参数", state="disabled")

        # 文件信息
        lf_file_info = ttk.LabelFrame(tab_params, text=" 文件信息 ")
        lf_file_info.pack(fill="x", padx=10, pady=5)
        lf_file_info.grid_columnconfigure(1, weight=1)
        ttk.Label(lf_file_info, text="文件名: ").grid(row=0,
                                                   column=0,
                                                   padx=10,
                                                   pady=5)
        ttk.Label(lf_file_info, textvariable=self.str_file_name).grid(row=0,
                                                                      column=1,
                                                                      padx=10)
        ttk.Label(lf_file_info, text="分辨率: ").grid(row=1,
                                                   column=0,
                                                   padx=10,
                                                   pady=5)
        ttk.Label(lf_file_info,
                  textvariable=self.str_file_resolution).grid(row=1,
                                                              column=1,
                                                              padx=10)

        # 参数调整
        lf_params_adjust = ttk.LabelFrame(tab_params, text=" 参数调整 ")
        lf_params_adjust.pack(fill="x", padx=10, pady=5)
        lf_params_adjust.grid_columnconfigure(2, weight=1)
        ttk.Label(lf_params_adjust).grid(row=0, column=0, padx=5)
        ttk.Label(lf_params_adjust).grid(row=0, column=3, padx=5)
        ttk.Label(lf_params_adjust, text="字幕区域起点: ").grid(row=0,
                                                          column=1,
                                                          sticky="e")
        self.scale_y_from = ttk.LabeledScale(lf_params_adjust,
                                             from_=0,
                                             to=0,
                                             variable=self.int_y_from)
        self.scale_y_from.grid(row=0, column=2, pady=5, sticky="ew")
        self.scale_y_from.scale.bind("<ButtonRelease-1>",
                                     self.__async_load_preview)
        ttk.Label(lf_params_adjust, text="字幕区域终点: ").grid(row=1,
                                                          column=1,
                                                          sticky="e")
        self.scale_y_to = ttk.LabeledScale(lf_params_adjust,
                                           from_=0,
                                           to=0,
                                           variable=self.int_y_to)
        self.scale_y_to.grid(row=1, column=2, pady=5, sticky="ew")
        self.scale_y_to.scale.bind("<ButtonRelease-1>",
                                   self.__async_load_preview)
        ttk.Label(lf_params_adjust, text="二值化阈值: ").grid(row=2,
                                                         column=1,
                                                         sticky="e")
        scale_bth = ttk.LabeledScale(lf_params_adjust,
                                     from_=150,
                                     to=255,
                                     variable=self.int_binary_threshold)
        scale_bth.grid(row=2, column=2, pady=5, sticky="ew")
        scale_bth.scale.bind("<ButtonRelease-1>", self.__async_load_preview)

        # 字幕区域及效果预览
        lf_preview = ttk.LabelFrame(tab_params, text=" 字幕区域及效果预览(拖动滑块选择帧) ")
        lf_preview.pack(fill="both", expand=True, padx=10, pady=5)
        self.lb_preview = ttk.Label(lf_preview, image=None, anchor="center")
        self.lb_preview.pack(fill="both", expand=True)
        self.scale_frame = ttk.LabeledScale(lf_preview,
                                            from_=0,
                                            to=0,
                                            variable=self.int_current_frame)
        self.scale_frame.pack(fill="x", padx=10, side="bottom")
        self.scale_frame.scale.bind("<ButtonRelease-1>",
                                    self.__async_load_preview)

        # 下一步
        fr_next = ttk.Frame(tab_params)
        fr_next.pack(fill="x", padx=10, pady=10)
        ttk.Button(fr_next,
                   text="下一步",
                   command=lambda: self.tab_control.select(2)).pack()
예제 #25
0
    def build_GUI(self):
        self.data_panel = ttk.Frame(self)
        self.knap_panel = ttk.Frame(self)
        self.lblGuitarer = ttk.Label(
            self.knap_panel,
            text='Der er {} guitarer i databasen'.format(None))
        self.lblGuitarer.grid(row=0, column=0)
        self.butUpdate = ttk.Button(self.knap_panel,
                                    text='Opdater',
                                    command=self.update_label)
        self.butUpdate.grid(row=1, column=0)

        self.lblName = ttk.Label(self.knap_panel, text='Navn')
        self.lblName.grid(row=0, column=1)
        self.enName = ttk.Entry(self.knap_panel)
        self.enName.grid(row=0, column=2)
        self.lblPris = ttk.Label(self.knap_panel, text='Pris')
        self.lblPris.grid(row=1, column=1)
        self.scPris = ttk.LabeledScale(self.knap_panel, from_=0, to=30000)
        #self.scPris.config(showvalue=1)
        self.scPris.grid(row=1, column=2)
        producenter = self.data.get_producent_liste()
        lblProducenter = ttk.Label(self.knap_panel, text='Producenter')
        lblProducenter.grid(row=2, column=1)
        self.cbProducenter = ttk.Combobox(self.knap_panel, values=producenter)
        self.cbProducenter.grid(row=2, column=2)
        self.butNew = ttk.Button(self.knap_panel,
                                 text='Tilføj ny guitar',
                                 command=self.add_new)
        self.butNew.grid(row=3, column=1, columnspan=2)

        self.lblCurrentName = ttk.Label(self.knap_panel, text='Navn: ')
        self.lblCurrentName.grid(row=0, column=3)
        self.lblCurrentMaerke = ttk.Label(self.knap_panel, text='Mærke: ')
        self.lblCurrentMaerke.grid(row=1, column=3)
        self.lblCurrentPris = ttk.Label(self.knap_panel, text='Pris: ')
        self.lblCurrentPris.grid(row=2, column=3)
        self.butDelete = ttk.Button(self.knap_panel,
                                    text='Fjern guitar',
                                    command=self.delete_current_guitar)
        self.butDelete.grid(row=3, column=3)

        self.db_view = ttk.Treeview(self.data_panel,
                                    column=("column1", "column2", "column3",
                                            "column4"),
                                    show='headings')
        self.db_view.bind("<ButtonRelease-1>", self.on_guitar_selected)
        self.db_view.heading("#1", text="Navn")
        self.db_view.heading("#2", text="Mærke")
        self.db_view.heading("#3", text="Pris")
        self.db_view.heading("#4", text="id")
        self.db_view["displaycolumns"] = ("column1", "column2", "column3")
        ysb = ttk.Scrollbar(self.data_panel,
                            command=self.db_view.yview,
                            orient=tk.VERTICAL)
        self.db_view.configure(yscrollcommand=ysb.set)
        self.db_view.pack(side=tk.TOP)

        self.data_panel.pack(side=tk.TOP)
        self.knap_panel.pack(side=tk.LEFT)
        self.pack()