2016-05-19 18 views
-1

Ich versuche eine GUI für mein Programm zu erstellen, aber ich habe meinen Code sehr geändert und ich habe gesehen, dass GUI ein Frame vermisst, aber vorher war es in Ordnung. Kann mir jemand helfen und sagen, warum ein Rahmen mit einem Knopf nicht auf der Unterseite erscheint?Tkinter zeigt keinen Frame an

Das gesamte Objekt "button_part" wird nicht angezeigt.

from tkinter import * 
import tkinter as tk 
import os 
import glob 

BOUNDS = ["Last week", "Last 2 weeks", "Last 3 weeks"] 


class settings_part: 
    path_to_copy = 0 

    def __init__(self, master, update_func): 
     path_to_copy = StringVar() 
     settings_frame = Frame(master, background="") 
     settings_frame.pack(side=TOP, fill=X) 
     date_bound = StringVar() 
     date_bound.set(BOUNDS[1]) 
     date_option = OptionMenu(settings_frame, date_bound, *BOUNDS, command=update_func) 
     date_option.config(background="#732c30") 
     date_option.config(foreground="white") 
     date_option.config(bd=0) 
     date_option.pack(side=LEFT, padx=5, pady=5) 

     path_to_copy.set("~/Python/usun") 
     box_with_path = Entry(settings_frame, textvariable=path_to_copy) 
     box_with_path.pack(side=RIGHT, padx=5, pady=5) 
     # s = path_to_copy.get() 


class songs_part: 
    def __init__(self, master, root): 
     self.songs_frame = Frame(master) 
     self.update_songs(root.list_of_songs) 
     self.songs_frame.pack() 

    def update_songs(self, l): 
     for song in l: 
      c = Checkbutton(self.songs_frame, text=song[0], variable=song[1]) 
      c.pack() 


class button_part: 
    def __init__(self, master, copyFunc): 
     self.button_frame = Frame(master) 
     btn_image = PhotoImage(file="copybtn.png") 
     self.copy_button = Button(self.button_frame, command=copyFunc, text="Copy", 
            image=btn_image, highlightthickness=0, bd=0, activebackground="#732c30") 
     self.copy_button.pack() 


class App: 

    def __init__(self): 
     root = Tk() 

     root.title("Copying songs") 
     root.geometry("500x500") 
     root.option_add("*Font", "Calibra") 
     back_image = PhotoImage(file="back.png") 

     self.window = Label(root, image=back_image) 
     self.window.pack(fill="both", expand="yes") 

     self.list_of_songs = list() 

     self.make_list_of_songs() 

     self.set_part = settings_part(self.window, self.update_list) 
     self.son_part = songs_part(self.window, self) 
     self.but_part = button_part(self.window, self.copy_songs) 

     root.mainloop() 

    def make_list_of_songs(self): 
     owd = os.getcwd() 
     os.chdir("/home/stanek/Music/usun") 
     for file in glob.glob("*.mp3"): 
      self.list_of_songs.append([file, tk.IntVar()]) 
     os.chdir(owd) 

    def copy_songs(self): 
     for s in self.list_of_songs: 
      print(s) 

    def update_list(self, arg): 
     print("updating list with songs from " + arg) 
     self.son_part = songs_part(self.window, self) 

if __name__ == '__main__': 
    App() 

Antwort

1

Sie packen nie den Knopfrahmen.

+0

Oh, danke! Wie auch immer, es zeigt kein Bild, sondern ein graues Rechteck:/Früher hat es funktioniert und das Bild ist ok:/ – siema

+1

ok, danke. Ich habe "btnimage" in "self.btnimage" geändert und es funktioniert, ist diese Lösung eine richtige? – siema