Exemple #1
0
class GUI():
    def __init__(self):
        self.root = ThemedTk(theme="radiance")
        INIT_WIDTH, INIT_HEIGHT = self.root.winfo_screenwidth(
        ), self.root.winfo_screenheight()
        boldStyle = ttk.Style()
        boldStyle.configure("Bold.TButton", font=('Sans', '12', 'bold'))
        #icon_loc = os.path.join(os.getcwd(),ICON_NAME)
        #img = ImageTk.PhotoImage(master = self.root, file=icon_loc)
        #self.root.wm_iconbitmap(img)
        #self.root.ttk.call('wm', 'iconphoto', self.root._w, img)
        self.root.title("Form Labeller")
        self.root.maxsize(INIT_WIDTH, INIT_HEIGHT)
        self.supported_formats = SUPPORTED_FORMATS

        self.left_frame = Frame(self.root, width=BUTTON_WIDTH)
        self.top_frame1 = Frame(self.left_frame,
                                width=BUTTON_WIDTH,
                                height=int(INIT_HEIGHT / 2))
        self.top_frame = Frame(self.left_frame,
                               width=BUTTON_WIDTH,
                               height=INIT_HEIGHT - int(INIT_HEIGHT / 2))
        self.bottom_frame = Frame(self.root, width=INIT_WIDTH - BUTTON_WIDTH)

        self.load_image_directory_button = Button(self.top_frame1,
                                                  text='Open Folder',
                                                  command=self.load_directory,
                                                  width=int(BUTTON_WIDTH),
                                                  style="Bold.TButton")
        self.load_image_directory_button.grid(row=OPEN_FOLDER_ROW,
                                              columnspan=2,
                                              sticky=tk.W + tk.E)

        self.prev_img_button = Button(self.top_frame1,
                                      text='← Prev',
                                      command=self.previous_img,
                                      state=tk.DISABLED,
                                      width=int(BUTTON_WIDTH / 2),
                                      style="Bold.TButton")
        self.prev_img_button.grid(row=PREV_ROW, column=0, sticky=tk.W + tk.E)

        self.next_img_button = Button(self.top_frame1,
                                      text='Next → ',
                                      command=self.next_img,
                                      width=int(BUTTON_WIDTH / 2),
                                      style="Bold.TButton")
        self.next_img_button.grid(row=NEXT_COL, column=1, sticky=tk.W + tk.E)

        self.save_image_button = Button(self.top_frame1,
                                        text='Save ',
                                        command=self.saver,
                                        width=int(BUTTON_WIDTH),
                                        style="Bold.TButton")
        self.save_image_button.grid(row=SAVE_ROW,
                                    columnspan=2,
                                    sticky=tk.W + tk.E)

        self.delete_poly_button = Button(self.top_frame,
                                         text='Delete Selected',
                                         command=self.delete_selected,
                                         width=int(BUTTON_WIDTH),
                                         style="Bold.TButton")
        self.delete_poly_button.grid(row=DEL_SELECTED_ROW,
                                     columnspan=2,
                                     sticky=tk.W + tk.E)

        self.type_choices = TYPE_CHOICES
        self.variable = StringVar(self.top_frame)
        self.variable.set(self.type_choices[0])
        self.type_options = OptionMenu(self.top_frame,
                                       self.variable,
                                       *self.type_choices,
                                       style="Bold.TButton")
        self.type_options.config(width=int(BUTTON_WIDTH / 2))
        self.type_options.grid(row=DROP_DOWN_ROW, column=0)

        self.save_type_button = Button(self.top_frame,
                                       text='Save Type',
                                       command=self.save_type,
                                       width=int(BUTTON_WIDTH / 2),
                                       style="Bold.TButton")
        self.save_type_button.grid(row=SAVE_TYPE_ROW,
                                   column=1,
                                   sticky=tk.W + tk.E)

        self.deselect_all_button = Button(self.top_frame,
                                          text='Deselect All',
                                          command=self.deselect_all,
                                          width=BUTTON_WIDTH,
                                          style="Bold.TButton")
        self.deselect_all_button.grid(row=DESELECT_ALL_ROW,
                                      columnspan=2,
                                      sticky=tk.W + tk.E)

        self.select_all_button = Button(self.top_frame,
                                        text='Select All',
                                        command=self.select_all,
                                        width=BUTTON_WIDTH,
                                        style="Bold.TButton")
        self.select_all_button.grid(row=SELECT_ALL_ROW,
                                    columnspan=2,
                                    sticky=tk.W + tk.E)

        self.draw_poly_button = Button(self.top_frame,
                                       text='Draw Poly',
                                       command=self.draw_poly_func,
                                       width=BUTTON_WIDTH,
                                       style="Bold.TButton")
        self.draw_poly_button.grid(row=DRAW_POLY_ROW,
                                   columnspan=2,
                                   sticky=tk.W + tk.E)

        self.draw_rect_button = Button(self.top_frame,
                                       text='Draw Rectangle',
                                       command=self.draw_rect_func,
                                       width=BUTTON_WIDTH,
                                       style="Bold.TButton")
        self.draw_rect_button.grid(row=DRAW_RECT_ROW,
                                   columnspan=2,
                                   sticky=tk.W + tk.E)

        self.delete_all_button = Button(self.top_frame,
                                        text='Delete All',
                                        command=self.delete_all,
                                        width=BUTTON_WIDTH,
                                        style="Bold.TButton")

        self.save_poly_button = Button(self.top_frame,
                                       text='Save Poly',
                                       command=self.save_drawing,
                                       width=int(BUTTON_WIDTH / 2),
                                       style="Bold.TButton")

        self.discard_poly_button = Button(self.top_frame,
                                          text='Discard Poly',
                                          command=self.discard_drawing,
                                          width=int(BUTTON_WIDTH / 2),
                                          style="Bold.TButton")

        self.save_rect_button = Button(self.top_frame,
                                       text='Save Rect',
                                       command=self.save_drawing,
                                       width=int(BUTTON_WIDTH / 2),
                                       style="Bold.TButton")

        self.discard_rect_button = Button(self.top_frame,
                                          text='Discard Rect',
                                          command=self.discard_drawing,
                                          width=int(BUTTON_WIDTH / 2),
                                          style="Bold.TButton")

        self.show_type_button = Button(self.top_frame,
                                       text='Show Type',
                                       command=self.show_type,
                                       width=int(BUTTON_WIDTH / 2),
                                       style="Bold.TButton")
        self.show_type_button.grid(row=SHOW_TYPE_ROW,
                                   column=0,
                                   columnspan=1,
                                   sticky=tk.W + tk.E)

        self.hide_type_button = Button(self.top_frame,
                                       text='Hide Type',
                                       command=self.hide_type,
                                       width=int(BUTTON_WIDTH / 2),
                                       style="Bold.TButton")
        self.hide_type_button.grid(row=HIDE_TYPE_ROW,
                                   columnspan=1,
                                   column=1,
                                   sticky=tk.W + tk.E)

        self.make_tight_button = Button(self.top_frame,
                                        text='Make Tight',
                                        command=self.make_tight,
                                        width=int(BUTTON_WIDTH / 2),
                                        style="Bold.TButton")
        self.make_tight_button.grid(row=MAKE_TIGHT_ROW,
                                    columnspan=2,
                                    column=0,
                                    sticky=tk.W + tk.E)

        self.threshold_scale = Scale(self.top_frame,
                                     from_=0,
                                     to=255,
                                     orient=HORIZONTAL,
                                     width=int(BUTTON_WIDTH / 2),
                                     label="Binary Threshold")
        self.threshold_scale.set(128)
        self.threshold_scale.grid(row=THRESHOLD_ROW,
                                  columnspan=2,
                                  column=0,
                                  sticky=tk.W + tk.E)

        self.tight_save_button = Button(self.top_frame,
                                        text='Accept Tight',
                                        command=self.save_tight)

        self.tight_discard_button = Button(self.top_frame,
                                           text='Discard Tight',
                                           command=self.discard_tight)

        self.canvas = Canvas(self.bottom_frame,
                             width=INIT_WIDTH - BUTTON_WIDTH,
                             height=INIT_HEIGHT,
                             borderwidth=1)
        self.image_name = None
        #self.image_path = os.path.join('imgs','img1.jpg')
        self.image_dir = None
        self.images_in_dir = None
        self.curr_idx = None
        self.img_cnv = None
        #self.img_cnv = ImageOnCanvas(self.root,self.canvas,self.image_path)
        self.drawing_obj = None
        self.tight_box_obj = None

        self.left_frame.pack(side=tk.LEFT)
        self.top_frame1.pack(side=tk.TOP)
        self.top_frame.pack(side=tk.BOTTOM)
        self.bottom_frame.pack(side=tk.LEFT)
        self.canvas.pack()
        self.hide_buttons()
        self.load_image_directory_button.config(state="normal")

    def save_tight(self):
        self.tight_box_obj.save_tight_box()
        self.tight_save_button.grid_forget()
        self.tight_discard_button.grid_forget()
        self.make_tight_button.grid(row=MAKE_TIGHT_ROW,
                                    columnspan=2,
                                    sticky=tk.W + tk.E)
        self.show_buttons()
        self.tight_box_obj = None

    def discard_tight(self):
        self.tight_box_obj.discard_tight_box()
        self.tight_save_button.grid_forget()
        self.tight_discard_button.grid_forget()
        self.make_tight_button.grid(row=MAKE_TIGHT_ROW,
                                    columnspan=2,
                                    sticky=tk.W + tk.E)
        self.show_buttons()
        self.tight_box_obj = None

    def show_type(self):
        for poly in self.img_cnv.polygons:
            if poly.select_poly:
                poly.show_type()

    def hide_type(self):
        for poly in self.img_cnv.polygons:
            poly.unshow_type()

    def hide_buttons(self):
        self.load_image_directory_button.config(state=tk.DISABLED)
        self.save_image_button.config(state=tk.DISABLED)
        self.delete_poly_button.config(state=tk.DISABLED)
        self.save_type_button.config(state=tk.DISABLED)
        self.deselect_all_button.config(state=tk.DISABLED)
        self.select_all_button.config(state=tk.DISABLED)
        self.delete_all_button.config(state=tk.DISABLED)
        self.show_type_button.config(state=tk.DISABLED)
        self.hide_type_button.config(state=tk.DISABLED)
        self.make_tight_button.config(state=tk.DISABLED)

    def show_buttons(self):
        self.load_image_directory_button.config(state="normal")
        self.save_image_button.config(state="normal")
        self.delete_poly_button.config(state="normal")
        self.save_type_button.config(state="normal")
        self.deselect_all_button.config(state="normal")
        self.select_all_button.config(state="normal")
        self.delete_all_button.config(state="normal")
        self.show_type_button.config(state="normal")
        self.hide_type_button.config(state="normal")
        self.draw_poly_button.config(state="normal")
        self.draw_rect_button.config(state="normal")
        self.make_tight_button.config(state="normal")

    def select_all(self):
        for poly in self.img_cnv.polygons:
            poly.select_polygon()

    def deselect_all(self):
        self.hide_type()
        for poly in self.img_cnv.polygons:
            poly.deselect_poly()

    def delete_all(self):
        result = messagebox.askyesno("Confirm Delete All",
                                     "Delete All Annotations?")
        if not result:
            return
        self.select_all()
        self.delete_selected()
        #self.img_cnv.polygons_mutex.acquire()
        #for poly in self.img_cnv.polygons:
        #    poly.delete_self()
        #self.img_cnv.polygons_mutex.release()

    def save_type(self):
        selected_option = self.variable.get()
        self.img_cnv.polygons_mutex.acquire()
        for poly in self.img_cnv.polygons:
            if poly.select_poly == True:
                if selected_option == "None":
                    poly.poly_type = None
                else:
                    poly.poly_type = selected_option
                #poly.unshow_type()
                #poly.show_type()
        self.img_cnv.polygons_mutex.release()
        self.variable.set(self.type_choices[0])
        #self.deselect_all()

    def load_new_img(self):
        self.canvas.delete('all')
        self.img_cnv = None
        path = os.path.join(self.image_dir, self.image_name)
        self.img_cnv = ImageOnCanvas(self.root, self.canvas, path)
        logger("LOADED: " + self.img_cnv.image_path)

    def load_directory(self):
        while True:
            selection = filedialog.askdirectory()
            if selection == () or selection == '':
                return
            self.root.directory = selection
            self.image_dir = self.root.directory
            file_names = os.listdir(self.image_dir)
            self.images_in_dir = []
            self.curr_idx = None
            self.image_name = None
            for name in file_names:
                if name.split('.')[-1] in self.supported_formats:
                    self.images_in_dir.append(name)
            if len(self.images_in_dir) == 0:
                self.pop_up("No supported images in the selected directory")
            else:
                break
        self.show_buttons()
        self.next_img()

    def pop_up(self, text):
        top = Toplevel()
        top.title("ERROR")
        msg = Message(top, text=text)
        msg.pack()
        button = Button(top, text="Dismiss", command=top.destroy)
        button.pack()

    def next_img(self):
        if self.curr_idx == None:
            self.curr_idx = -1
        self.curr_idx = self.curr_idx + 1
        if self.curr_idx >= len(self.images_in_dir):
            self.pop_up("Done with Images in this directory")
            self.curr_idx = self.curr_idx - 1
            return
        if self.curr_idx > 0:
            self.prev_img_button.config(state="normal")
        self.image_name = self.images_in_dir[self.curr_idx]
        self.load_new_img()
        self.root.title("Form Labeller - " + self.image_name + "(" +
                        str(self.curr_idx + 1) + "/" +
                        str(len(self.images_in_dir)) + ")")

    def previous_img(self):
        if self.curr_idx == 1:
            self.curr_idx = -1
            self.prev_img_button.config(state=tk.DISABLED)
        else:
            self.curr_idx = self.curr_idx - 2
        self.next_img()

    def delete_selected(self):
        to_be_deleted = []
        for i, poly in enumerate(self.img_cnv.polygons):
            if poly.select_poly == True:
                poly.delete_self()
                to_be_deleted.append(i)
        j = 0
        for idx in to_be_deleted:
            self.img_cnv.polygons.pop(idx - j)
            self.img_cnv.bbs.pop(idx - j)
            self.img_cnv.poly_type.pop(idx - j)
            j = j + 1

    def start_gui(self):
        self.root.mainloop()

    def saver(self):
        logger("Saving: " + self.img_cnv.image_path)
        self.save_image_button.config(state=tk.DISABLED)
        self.img_cnv.save_json(self.root.directory)
        self.save_image_button.config(state="normal")

    def draw_poly_func(self):
        self.deselect_all()
        self.img_cnv.drawing_polygon = True
        self.draw_poly_button.grid_forget()
        self.save_poly_button.grid(row=DRAW_POLY_ROW,
                                   column=0,
                                   sticky=tk.W + tk.E)
        self.discard_poly_button.grid(row=DRAW_POLY_ROW,
                                      column=1,
                                      sticky=tk.W + tk.E)
        self.hide_buttons()
        self.draw_rect_button.config(state=tk.DISABLED)
        self.drawing_obj = DrawPoly(self.bottom_frame, self.canvas,
                                    self.img_cnv, RADIUS)

    def draw_rect_func(self):
        self.deselect_all()
        self.img_cnv.drawing_polygon = True
        self.draw_rect_button.grid_forget()
        self.save_rect_button.grid(row=DRAW_RECT_ROW,
                                   column=0,
                                   sticky=tk.W + tk.E)
        self.discard_rect_button.grid(row=DRAW_RECT_ROW,
                                      column=1,
                                      sticky=tk.W + tk.E)
        self.hide_buttons()
        self.draw_poly_button.config(state=tk.DISABLED)
        self.drawing_obj = DrawRect(self.bottom_frame, self.canvas,
                                    self.img_cnv, RADIUS)

    def save_drawing(self):
        self.show_buttons()
        self.img_cnv.drawing_polygon = False
        new_poly_pts = self.drawing_obj.pt_coords
        print("Trying to save polygon with pts:", str(new_poly_pts))
        for pt in self.drawing_obj.points:
            self.canvas.delete(pt)
        if self.img_cnv.scale_factor != None:
            for i in range(len(new_poly_pts)):
                for j in range(2):
                    new_poly_pts[i][
                        j] = new_poly_pts[i][j] / self.img_cnv.scale_factor
        self.img_cnv.add_poly(new_poly_pts)
        #self.img_cnv.bbs.append(new_poly_pts)
        #self.img_cnv.draw_bbs([self.img_cnv.bbs[-1]])
        #debug (1, str(type(self.drawing_obj)))
        if isinstance(self.drawing_obj, DrawRect):
            self.save_rect_button.grid_forget()
            self.discard_rect_button.grid_forget()
            self.draw_rect_button.grid(row=DRAW_RECT_ROW,
                                       columnspan=2,
                                       sticky=tk.W + tk.E)
        elif isinstance(self.drawing_obj, DrawPoly):
            self.save_poly_button.grid_forget()
            self.discard_poly_button.grid_forget()
            self.draw_poly_button.grid(row=DRAW_POLY_ROW,
                                       columnspan=2,
                                       sticky=tk.W + tk.E)
        self.drawing_obj.delete_self()
        self.drawing_obj = None

    def discard_drawing(self):
        self.show_buttons()
        self.img_cnv.drawing_polygon = False
        #for pt in self.drawing_obj.points:
        #    self.canvas.delete(pt)
        self.drawing_obj.delete_self()
        if isinstance(self.drawing_obj, DrawRect):
            self.save_rect_button.grid_forget()
            self.discard_rect_button.grid_forget()
            self.draw_rect_button.grid(row=DRAW_RECT_ROW,
                                       columnspan=2,
                                       sticky=tk.W + tk.E)
        elif isinstance(self.drawing_obj, DrawPoly):
            self.save_poly_button.grid_forget()
            self.discard_poly_button.grid_forget()
            self.draw_poly_button.grid(row=DRAW_POLY_ROW,
                                       columnspan=2,
                                       sticky=tk.W + tk.E)
        self.drawing_obj = None

    def make_tight(self):
        self.hide_buttons()
        self.tight_box_obj = TightBox(self.root, self.img_cnv,
                                      self.threshold_scale.get())
        self.tight_box_obj.tight_box()
        self.make_tight_button.grid_forget()
        self.tight_save_button.grid(row=MAKE_TIGHT_ROW,
                                    column=0,
                                    columnspan=1,
                                    sticky=tk.W + tk.E)
        self.tight_discard_button.grid(row=MAKE_TIGHT_ROW,
                                       column=1,
                                       columnspan=1,
                                       sticky=tk.W + tk.E)
from ttkthemes import ThemedTk, THEMES
from tkinter import ttk
conversion_can_do = ('png', 'gif', 'tiff', 'ico', 'jpg', 'bmp'
                     )  # Formats That This Converter Can Do.
conversion_can_do_with_pdf = ('png', 'gif', 'tiff', 'ico', 'jpg', 'bmp', 'pdf'
                              )  # Formats That This Converter Can Do.
from tkinter import filedialog
from PIL import Image
import os  # arc
root = ThemedTk(themebg=True)  # Our Main Window.
root.set_theme('arc')
opend_file_path = ttk.Label(
    root, text=None)  # Creating Label For Showing Path Of Opened File.
saved_file_path = ttk.Label(
    root, text=None)  # Creating Label For Showing Path Of Saved File.
root.maxsize(500, 200)  # Maxsize Of Our Window is height=400,width=200
root.minsize(500, 200)  # Minsize Of Our Window is height=400,width=200
Slect_FILE_FROM_DONW_BELOW_OPTIOn = ttk.Label(
    root,
    text=
    'Select A Fromat To Import From Down Below Than Select File Type To Save'
)  # This Is Our Heading That Tells How To Use This Converter.
Slect_FILE_FROM_DONW_BELOW_OPTIOn.pack(
)  # Showing Our Label In Our Main Window That Means I Am Packing The Label.


def tkinter_window_is_closed(
):  # A Function That Ask Are You Sure Quit? When User Closes The Window.
    from tkinter import messagebox  # Importing messagebox For Asking Question.
    question = messagebox.askquestion('?',
                                      'Are You Sure Quit?')  # This Is Question
from tkinter import messagebox
from pytube import YouTube
from PIL import ImageTk, Image
import requests
import urllib.parse
import io
import time
from tkinter import filedialog
import os
import threading


root = ThemedTk(theme="radiance")
root.title("Youtbe video downloader")
root.geometry('670x340')
root.maxsize(670, 340)
root.minsize(670, 340)
root.iconbitmap('images/youtube-downloader.ico')
root.configure(bg='#100E17')

text = tk.Label(root, text="Download Video and Audio from YouTube",
                font='Helvetica 15 bold', bg="#100E17", fg="white")
text.pack()

status = tk.Label(root, text="Status bar", font='Helvetica 10',
                  relief='sunken', anchor="w",bg="#312D3C",fg="white")
status.pack(side="bottom", fill='x')

# Creating threads

Exemple #4
0
class Toplevel1:
    def __init__(self):
        '''This class configures and populates the toplevel window.
		   top is the toplevel containing window.'''
        # _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        # _fgcolor = '#000000'  # X11 color: 'black'
        # _compcolor = '#d9d9d9' # X11 color: 'gray85'
        # _ana1color = '#d9d9d9' # X11 color: 'gray85'
        # _ana2color = '#ececec' # Closest X11 color: 'gray92'
        self.style = ttk.Style()
        # if sys.platform == "win32":
        #     self.style.theme_use('winnative')
        # self.style.configure('.',background=_bgcolor)
        # self.style.configure('.',foreground=_fgcolor)
        # self.style.configure('.',font="TkDefaultFont")
        # self.style.map('.',background=
        #     [('selected', _compcolor), ('active',_ana2color)])
        self.root = ThemedTk(theme="arc")
        # self.root = tk.Tk()

        self.root.geometry("1200x661+284+114")
        self.root.minsize(120, 1)
        self.root.maxsize(1924, 1061)
        self.root.resizable(1, 1)
        self.root.title("New Toplevel")
        # top.configure(background="#d9d9d9")
        #
        # self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        # top.configure(menu = self.menubar)

        # self.style.configure('TNotebook.Tab', background=_bgcolor)
        # self.style.configure('TNotebook.Tab', foreground=_fgcolor)
        # self.style.map('TNotebook.Tab', background=
        #     [('selected', _compcolor), ('active',_ana2color)])
        self.TNotebook1 = ttk.Notebook(self.root)
        self.TNotebook1.place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0)
        self.TNotebook1.configure(takefocus="")
        self.TNotebook1_t1 = tk.Frame(self.TNotebook1)
        self.TNotebook1.add(self.TNotebook1_t1, padding=3)
        self.TNotebook1.tab(
            0,
            text="Page 1",
            compound="left",
            underline="-1",
        )
        self.TNotebook1_t2 = tk.Frame(self.TNotebook1)
        self.TNotebook1.add(self.TNotebook1_t2, padding=3)
        self.TNotebook1.tab(
            1,
            text="Page 2",
            compound="left",
            underline="-1",
        )
        self.f = tk.Frame(self.TNotebook1_t1, width=20, height=100, bg="red")
        self.f.place(x=0, y=0)

        # self.f2 = tk.Frame(self.TNotebook1_t1, width=20, height=100, bg="blue")
        # self.f2.place(x=0, y=600,anchor="nw")
        # self.set_label()

    def inner(self):
        # while 1:
        time.sleep(3)
        lb = ttk.Label(self.f, text=1)
        lb.pack()

    def wapr(self):
        self.inner()

    def set_label(self):
        p = Process(target=self.wapr())
        p.start()

    #
    # def set_label(self): # 使用这个会报错 pickle 不能序列化lambda
    # 	p = Process(target=self.inner) # Call unbound method with explicit self
    # 	p.start()                      # Can't pickle 'tkapp' object

    def set_button(self):
        button = tk.Button(self.TNotebook1_t1,
                           text="bt",
                           command=self.set_label)
        button.pack()
Exemple #5
0
        check = (star_a.endswith('.mp4'))
        check_ = (star_a.endswith('.avi'))
        check_1 = (star_a.endswith('.ogv'))
        if check == True:
            convert_button.config(command=video_to_audio)
            convert_button.config(state=NORMAL)
            open_file_path.config(text=f'Opened File Path:-{path_opend_file_}')
        if check_ == True:
            convert_button.config(command=video_to_audio)
            convert_button.config(state=NORMAL)
            open_file_path.config(text=f'Opened File Path:-{path_opend_file_}')
        if check_1 == True:
            convert_button.config(command=video_to_audio)
            convert_button.config(state=NORMAL)
            open_file_path.config(text=f'Opened File Path:-{path_opend_file_}')
    except Exception:
        convert_button.config(state=DISABLED)


r.minsize(500, 200)
r.maxsize(500, 200)
r.title('Video To Audio')
r.geometry('500x200')
heading = ttk.Label(r, text='Video File to Audio File ', font=('Font', 10))
heading.place(x=100 + 25 + 5 + 5 + 5 + 15, y=1)
browse_mp4 = ttk.Button(r, text='Browse A Video File', command=dialog_video)
browse_mp4.place(x=172, y=55)
mainloop()
# -----------------------------------------------------
# ----------------------------------------
Exemple #6
0
class Application:
    """窗口主类"""
    def __init__(self):
        self.data = None  # UI界面数据,可以将这部分完全转移至Main
        self.thread = False  # 表示当前是否有线程在运行
        self.setroot()
        self.setui(self.root)

    # ——————————————————————————————————————————————————————————
    # 初始化函数
    def setroot(self):
        """创建主窗口"""
        self.root = ThemedTk(theme="arc", toplevel=True, themebg=True)
        self.root.update()
        x_max, y_max = self.root.maxsize()
        x, y = int(x_max / 2 - 300), int(y_max / 2 - 200)
        self.root.geometry("600x400+%s+%s" % (x, y))  # 居中显示
        self.root.title("Spyder")
        self.root.resizable(0, 0)  # 锁定长宽大小

        # 创建变量
        self.key = tk.StringVar()
        self.website = tk.StringVar()

    def setui(self, master):
        """创建窗口组件"""
        # ViewBox
        self.ViewBox = tk.LabelFrame(master,
                                     text="Result",
                                     width=420,
                                     height=360)
        self.ViewBox.place(x=20, y=20)
        self.view = ttk.Treeview(self.ViewBox,
                                 show='headings',
                                 column=('num', 'ct', 'zy', 'lj', 'rd'))
        self.view.place(x=0, y=0, width=400, relheight=1)

        # InfoBox
        self.InfoBox = tk.LabelFrame(master,
                                     text=u"Option",
                                     width=120,
                                     height=360)
        self.InfoBox.place(x=460, y=20)
        tk.Label(self.InfoBox, text="Website").place(x=10, y=20)
        self.Web = ttk.Combobox(
            self.InfoBox,
            textvariable=self.website,
            values=["WeiboSearch", "ZhihuSearch", "ZhihuBank", "BaiduNews"],
            width=11,
            state="readonly")
        self.Web.current(0)
        self.Web.place(x=10, y=50)
        tk.Label(self.InfoBox, text="Key").place(x=10, y=90)
        self.Key = tk.Entry(self.InfoBox,
                            highlightcolor="sky blue",
                            highlightthickness=1,
                            textvariable=self.key,
                            width=13)
        self.Key.place(x=10, y=120)
        self.Confirm = tk.Button(self.InfoBox,
                                 text="Update",
                                 width=9,
                                 height=1)
        self.Confirm.place(x=20, y=160)
        self.Clear = tk.Button(self.InfoBox,
                               text="Clear",
                               width=9,
                               command=self.clrview)
        self.Clear.place(x=20, y=200)
        self.Save = tk.Button(self.InfoBox, text="Save", width=9)
        self.Save.place(x=20, y=240)

        # TreeView
        self.view.heading(column="num", text="Num")
        self.view.heading(column="ct", text="Entry")
        self.view.heading(column="zy", text="Excerpt")
        self.view.heading(column="lj", text="Link")
        self.view.heading(column="rd", text="Hot")
        self.view.column("num", width=30, anchor=tk.W)
        self.view.column("ct", width=100, anchor=tk.W)
        self.view.column("zy", width=110, anchor=tk.W)
        self.view.column("lj", width=80, anchor=tk.W)
        self.view.column("rd", width=80, anchor=tk.W)

        # 信号槽(暂无必要)

    # ——————————————————————————————————————————————————————————
    # 功能函数

    def setdata(self, data):
        """设置当前数据表数据"""
        std_data = self.standardlize(data)
        self.data = std_data

    def clrdata(self):
        """清除数据"""
        self.data = None

    def standardlize(self, data):
        """将不同格式的数据统一格式"""
        table = pd.DataFrame({
            "序号": [],
            "词条": [],
            "摘要": [],
            "链接": [],
            "热度": []
        })
        table = table.merge(data, how="outer")
        table['序号'] = data.index.values + 1
        table.fillna("", inplace=True)
        table = table[["序号", "词条", "摘要", "链接", "热度"]]
        return table.values.tolist()

    def viewsort(col, reverse):
        """表格排序,暂未绑定"""
        l = [(self.view.set(k, col), k) for k in self.view.get_children('')]
        l.sort(reverse=reverse)

        # rearrange items in sorted positions
        for index, (val, k) in enumerate(l):
            self.view.move(k, '', index)

        # reverse sort next time
        self.view.heading(
            col,
            text=col,
            command=lambda _col=col: treeview_sort_column(_col, not reverse))

    def savefile(self):
        """选择保存文件的路径"""
        filename = filedialog.asksaveasfilename(initialdir=".",
                                                initialfile="Data.xlsx",
                                                defaultextension="xlsx",
                                                filetypes=[("数据表", ".xls"),
                                                           ("数据表", ".xlsx")])
        return filename

    def clrview(self):
        """清除数据表数据"""
        items = self.view.get_children()
        for item in items:
            self.view.delete(item)

    def update(self, func):
        """通过线程运行命令"""
        if not self.thread:
            self.thread = True
            t = threading.Thread(target=func)
            t.start()
        else:
            t = threading.Thread(target=lambda: msg.showinfo(
                title="Info", message="程序正在运行中,请稍后再试!"))

    def updatedata(self):
        """刷新数据表数据"""
        if self.data == None:
            msg.showwarning(title="Warning",
                            message="None Data!Please fetch first!")
        else:
            self.clrview()
            for d in self.data:
                self.view.insert('', tk.END, values=d)  # 添加数据到末尾
            self.thread = False

    def themechose(self, theme="arc"):
        """更换主题,包括'arc','adapta','aqua','breeze'"""
        self.root.configure(theme=theme)

    def mainloop(self):
        """窗口挂起"""
        self.root.mainloop()
Exemple #7
0
class Toplevel1:
    def __init__(self):
        '''This class configures and populates the toplevel window.
		   top is the toplevel containing window.'''
        self.style = ttk.Style()
        self.root = ThemedTk(theme="arc")
        # self.root = tk.Tk()
        self.root.geometry("1200x661+284+114")
        self.root.minsize(120, 1)
        self.root.maxsize(1924, 1061)
        self.root.resizable(1, 1)
        self.root.title("New Toplevel")
        # top.configure(background="#d9d9d9")
        #
        # self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        # top.configure(menu = self.menubar)

        # self.style.configure('TNotebook.Tab', background=_bgcolor)
        # self.style.configure('TNotebook.Tab', foreground=_fgcolor)
        # self.style.map('TNotebook.Tab', background=
        #     [('selected', _compcolor), ('active',_ana2color)])
        self.TNotebook1 = ttk.Notebook(self.root)
        self.TNotebook1.place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0)
        self.TNotebook1.configure(takefocus="")
        self.TNotebook1_t1 = tk.Frame(self.TNotebook1)
        self.TNotebook1.add(self.TNotebook1_t1, padding=3)
        self.TNotebook1.tab(
            0,
            text="Page 1",
            compound="left",
            underline="-1",
        )
        self.TNotebook1_t2 = tk.Frame(self.TNotebook1)
        self.TNotebook1.add(self.TNotebook1_t2, padding=3)
        self.TNotebook1.tab(
            1,
            text="Page 2",
            compound="left",
            underline="-1",
        )
        self.f = tk.Frame(self.TNotebook1_t1, width=20, height=100)
        self.f.place(x=0, y=0)
        self.set_button()

        # self.f2 = tk.Frame(self.TNotebook1_t1, width=20, height=100, bg="blue")
        # self.f2.place(x=0, y=600,anchor="nw")
        # self.set_label()

    def set_button(self):
        button = tk.Button(self.TNotebook1_t1,
                           text="bt",
                           command=self.add_label_thread)
        button.pack()

    def add_label(self):
        while True:

            lb = tk.Button(self.f, text=1)
            lb.pack()
            time.sleep(2)

    def add_label_thread(self):
        p = Thread(target=self.add_label)
        p.start()
import tkinter as tk
from tkinter import ttk  # Normal Tkinter.* widgets are not themed!
from ttkthemes import ThemedTk
from tkinter import messagebox
import pygame
from tkinter.filedialog import askopenfilename
import os
from mutagen.mp3 import MP3

pygame.init()

root = ThemedTk(theme="radiance")
root.title("Melody")
root.iconbitmap('images/melody_icon.ico')
root.geometry('620x300')
root.maxsize(620, 300)
root.minsize(620, 300)
text = tk.Label(root, text="Melody Music Player", font='Helvetica 18 bold')
text.pack()

status = tk.Label(root, text="Status bar", font='Helvetica 9',
                  relief='sunken', anchor="w")
status.pack(side="bottom", fill='x')

mp3_len_show = ttk.Label(root, text="", font='Helvetica 11')
mp3_len_show.pack()


def about_us():
    tk.messagebox.showinfo("Message", "This is About Us!")