简体   繁体   中英

Why doesn't the up/down slider bar work? Python Tkinter

the slider does not work, it draws it, but the command does not work. I tried all the methods on the Internet, and they do not work. I can't understand the very essence of the problem, tk. tkinter itself does not throw errors, and neither does Python itself. I read the documentation and didn't see anything useful.

from tkinter.ttk import Combobox
from tkinter import *
from tkinter import messagebox
from json import load, dump

windowset = Tk()

def _save():
    messagebox.showinfo('Settings Answer', 'Changes saved')

class _settings():
    global combo
    global combo2
    global combo3
    global combo4
    global combo5
    global combo6
    global combo7
    global combo8
    global combo9
    global combo10
    global combo11
    global combo12
    global combo13
    global combo14
    def _replace_bg():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_background"] = '{}'.format(combo.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_banner():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_banner"] = '{}'.format(combo2.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entryip():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entryip"] = '{}'.format(combo3.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entryipbg():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entryipbg"] = '{}'.format(combo4.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entrymac():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entrymac"] = '{}'.format(combo5.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entrymacbg():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entrymacbg"] = '{}'.format(combo6.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entrynumber():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entrynumber"] = '{}'.format(combo7.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_entrynumberbg():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_entrynumberbg"] = '{}'.format(combo8.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_banner_ip():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_ip"] = '{}'.format(combo9.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_banner_mac():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_mac"] = '{}'.format(combo10.get()) 
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_banner_number_phone():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["_numberphone"] = '{}'.format(combo11.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_button_ip():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["schemabuttons"]["_butt_ip"] = '{}'.format(combo12.get())
        finally:
            with open(r'files\config', 'w') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_button_mac():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["schemabuttons"]["_butt_mac"] = '{}'.format(combo13.get())
        finally:
            with open(r'files\config') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    def _replace_color_button_number_phone():
        try:
            with open(r'files\config') as f:
                data=load(f)
            data["MainWindow"]["_colortext"]["schemabuttons"]["_butt_number"] = '{}'.format(combo14.get())
        finally:
            with open(r'files\config') as f2:
                dump(data, f2, indent=4, sort_keys=True)
            _save()
    windowset.title('Settings')
    #windowset.iconbitmap(r'files\Settings.ico')
    windowset.configure(background='black')
    scrollbar = Scrollbar(windowset)
    scrollbar.pack(side=RIGHT, fill='y')
    listbox = Listbox(windowset, yscrollcommand=scrollbar.set)
    try:
        try:
            # Block 1
            combo = Combobox(windowset)
            banner = Label(
                            windowset, 
                            text='Choose a background color', 
                            fg='white', 
                            bg='Black', 
                            font=(
                                    'Arial Bold', 
                                    10
                            )
            )
            combo['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            combo.current(2)
            butt = Button(
                            windowset, 
                            text='Set BackGround', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_bg
            )
            #
            # Block 2
            lbl = Label(
                            windowset, 
                            text='\nChange text color of `Spider-Breaking` banner', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial Bold', 
                                    10
                            )
            )
            combo2 = Combobox(windowset)
            combo2['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt2 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_banner, 
                            width=9, 
                            height=0
            )
            #
            # Block 3
            lbl2 = Label(
                            windowset, 
                            text='\nChange text color `Entry IP-Address`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo3 = Combobox(windowset)
            combo3['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt3 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entryip, 
                            width=9, 
                            height=0
            )
            #
            # Block 4
            lbl3 = Label(
                            windowset, 
                            text='\nChange color `Entry Background IP-Address`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo4 = Combobox(windowset)
            combo4['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt4 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entryipbg, 
                            width=9, 
                            height=0
            )
            #
            # Block 5
            lbl4 = Label(
                            windowset, 
                            text='\nChange text color `Entry MAC-Address`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo5 = Combobox(windowset)
            combo5['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt5 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entrymac, 
                            width=9, 
                            height=0
            )
            #
            # Block 6
            lbl5 = Label(
                            windowset, 
                            text='\nChange color `Entry Background MAC-Address`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo6 = Combobox(windowset)
            combo6['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt6 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entrymacbg, 
                            width=9, 
                            height=0
            )
            # 
            # Block 7
            lbl6 = Label(
                            windowset, 
                            text='\nChange text color `Entry Number Phone`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo7 = Combobox(windowset)
            combo7['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt7 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entrynumber, 
                            width=9, 
                            height=0
            )
            #
            # Block 8
            lbl7 = Label(
                            windowset, 
                            text='\nChange color `Entry Background Number Phone`', 
                            fg='white', 
                            bg='black', 
                            font=(
                                    'Arial', 
                                    10
                            )
            )
            combo8 = Combobox(windowset)
            combo8['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt8 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_entrynumberbg, 
                            width=9, 
                            height=0
            )
            #
            # Block 9
            lbl8 = Label(
                            windowset, 
                            text='\nChange color banner `IP`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo9 = Combobox(windowset)
            combo9['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt9 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_banner_ip, 
                            width=9, 
                            height=0
            )
            #
            # Block 10
            lbl9 = Label(
                            windowset, 
                            text='\nChange color banner `MAC`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo10 = Combobox(windowset)
            combo10['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt10 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_banner_mac, 
                            width=9, 
                            height=0
            )
            #
            # Block 11
            lbl10 = Label(
                            windowset, 
                            text='\nChange color banner `Number Phone`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo11 = Combobox(windowset)
            combo11['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt11 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_banner_number_phone, 
                            width=9, 
                            height=0
            )
            #
            # Block 12
            lbl11 = Label(
                            windowset, 
                            text='\nChange color button `IP`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo12 = Combobox(windowset)
            combo12['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt12 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_button_ip, 
                            width=9, 
                            height=0
            )
            #
            # Block 13
            lbl12 = Label(
                            windowset, 
                            text='\nChange color button `MAC`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo13 = Combobox(windowset)
            combo13['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt13 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            command=_replace_color_button_mac, 
                            width=9, 
                            height=0
            )
            # 
            # Block 14
            lbl13 = Label(
                            windowset, 
                            text='\nChange color button `Number Phone`', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ), 
                            fg='white', 
                            bg='black'
            )
            combo14 = Combobox(windowset)
            combo14['values'] = ('pink', 'green', 'black', 'red', 'grey', 'blue', 'yellow')
            butt14 = Button(
                            windowset, 
                            text='Set', 
                            font=(
                                    'Arial Bold', 
                                    10
                            ),
                            command=_replace_color_banner_number_phone, 
                            width=9, 
                            height=0
            )
            #
            #/MAIN\
            __all__block = [combo, banner, butt,combo2, lbl, butt2,combo3, lbl2, butt3,combo4, lbl3, butt4,combo5, lbl4, butt5,combo6, lbl5, butt6,combo7, lbl6, butt7,combo8, lbl7, butt8,combo9, lbl8, butt9,combo10, lbl9, butt10,
                            combo11, lbl10, butt11,combo12,lbl11,butt12,combo13,lbl12,butt13,combo14, lbl13, butt14]
            for i in __all__block:
                listbox.insert('end', i.pack())
            listbox.pack()
            #/END\
        except Exception as Ex:
            print(Ex)
    finally:
        scrollbar.config(command=listbox.yview)
        windowset.mainloop()

Consider this block of code:

for i in __all__block:
    listbox.insert('end', i.pack())

It is calling pack() on every widget created in the prior block of code. pack() returns None , so you are inserting None inside the listbox over and over and over. Inserting None results in nothing getting added to the listbox.

The listbox can only scroll text items added with the insert method. It won't scroll widgets added using pack , place , or grid .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM