#πŸ”’ TKinter + TTK | Incorrect positioning.

14 messages Β· Page 1 of 1 (latest)

undone radish
#

Code:

import tkinter, pygame, os
from tkinter import ttk

pygame.mixer.init()
working_dir = os.getcwd() + '/data'
global_data = {'folders': {}, 'songs': {}, 'current_song_length': 0}
settings = {'paused': False, 'looped': False, 'shuffle': False, 'volume': 1}

def convert_seconds(seconds):
    return time.strftime('%M:%S', time.gmtime(seconds))
    
def fetch_files():
    global global_data

    for playlist in os.listdir(working_dir):
        path = os.path.join(working_dir, playlist)
        mp3_files = [file for file in os.listdir(path) if file.lower().endswith('.mp3')]
        # later

root = tkinter.Tk()
root.title('kade mp3 player')
root.geometry('400x200')    
root.resizable(width=False, height=False)

# song_tree = ttk.Treeview(height=6).grid()
control_buttons = ttk.Frame(root).place(relx=0, rely=1, anchor='sw', y=-5, x=10)
prev_button = ttk.Button(control_buttons, text='<<', width=3).grid(row=0, column=1, padx=2)
play_button = ttk.Button(control_buttons, text='||', width=3).grid(row=0, column=2, padx=2)
next_button = ttk.Button(control_buttons, text='>>', width=3).grid(row=0, column=3, padx=2)
loop_button = ttk.Button(control_buttons, text='[]', width=3).grid(row=0, column=4, padx=2)
shfl_button = ttk.Button(control_buttons, text='XX', width=3).grid(row=0, column=5, padx=2)

print('huh')
fetch_files()
root.mainloop()

Issue: the control_buttons refuses to leave topleft corner.

quartz stoneBOT
#

@undone radish

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

undone radish
bleak sonnet
#

The issue is with the placement of the control_buttons frame and the place() layout method you are using

#

control_buttons = ttk.Frame(root)
control_buttons.grid(row=1, column=0, pady=10, sticky="sw")

#

prev_button = ttk.Button(control_buttons, text='<<', width=3)
prev_button.grid(row=0, column=0, padx=2)

#

you can use this code

undone radish
#

ohh. alright

undone radish
#
control_buttons = ttk.Frame(root)
control_buttons.grid(row=1, column=0, pady=0, sticky="sw")
prev_button = ttk.Button(control_buttons, text='<<', width=3).grid(row=0, column=0, padx=2)
play_button = ttk.Button(control_buttons, text='||', width=3).grid(row=0, column=1, padx=2)
next_button = ttk.Button(control_buttons, text='>>', width=3).grid(row=0, column=2, padx=2)
loop_button = ttk.Button(control_buttons, text='[]', width=3).grid(row=0, column=3, padx=2)
shfl_button = ttk.Button(control_buttons, text='XX', width=3).grid(row=0, column=4, padx=2)
#

fixed it

#

thanks

quartz stoneBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.