示例#1
0
    def __init__(self, master):
        fr = Frame(master)
        master.title('Button Test')
        fr.grid(column=0, row=0, sticky=('nsew'))
        ## uncomment following 4 lines if you are running tkinter 8.5
        # im1 =  = Image.open('../images/butImage.png') ##
        # im2 = Image.open('../images/butImageTrans.png') ##
        # self.buttonPhoto = ImageTk.PhotoImage(im1)  ##
        # buttonPhotoTrans = ImageTk.PhotoImage(im2)  ##

        ## comment out following 2 lines if you are running tkinter 8.5
        self.buttonPhoto = PhotoImage(file='../images/butImage.png')  ##
        buttonPhotoTrans = PhotoImage(file='../images/butImageTrans.png')  ##
        '''
        we are using both a local and a variable prefixed with self
        '''
        but = Button(master, image=self.buttonPhoto)
        #but.image = self.buttonPhoto - not needed because using self
        but.grid(column=0, row=0, sticky=('ew'), padx=10, pady=10)
        myButton = Button(master,
                          compound='center',
                          text='Click on Me!',
                          style='new.TButton',
                          image=buttonPhotoTrans)
        myButton.image = buttonPhotoTrans  # keep a reference as local variable!
        myButton.grid(column=0, row=1, sticky=('ew'), padx=10, pady=10)
        myButton2 = Button(master,
                           compound='center',
                           text='Really long now - Click on Me!',
                           style='new.TButton',
                           image=buttonPhotoTrans)
        myButton2.image = buttonPhotoTrans  # keep a reference as local variable!
        myButton2.grid(column=0, row=2, sticky=('ew'), padx=10, pady=10)
示例#2
0
 def update_button(self, button: ttk.Button, image: "ImageTk",
                   node_draw: NodeDraw):
     logging.debug("update button(%s): %s", button, node_draw)
     self.hide_pickers()
     button.configure(image=image)
     button.image = image
     self.app.canvas.mode = GraphMode.NODE
     self.app.canvas.node_draw = node_draw
示例#3
0
 def scale_button(
     self, button: ttk.Button, image_enum: ImageEnum = None, image_file: str = None
 ) -> None:
     image = None
     if image_enum:
         image = self.app.get_icon(image_enum, TOOLBAR_SIZE)
     elif image_file:
         image = self.app.get_custom_icon(image_file, TOOLBAR_SIZE)
     if image:
         button.config(image=image)
         button.image = image
示例#4
0
文件: toolbar.py 项目: q9512268/core
 def update_button(
     self,
     button: ttk.Button,
     node_draw: NodeDraw,
     type_enum: NodeTypeEnum,
     image: PhotoImage,
 ) -> None:
     logging.debug("update button(%s): %s", button, node_draw)
     button.configure(image=image)
     button.image = image
     self.app.canvas.node_draw = node_draw
     if type_enum == NodeTypeEnum.NODE:
         self.current_node = node_draw
     elif type_enum == NodeTypeEnum.NETWORK:
         self.current_network = node_draw
示例#5
0
文件: toolbar.py 项目: montag451/core
 def update_button(
     self,
     button: ttk.Button,
     image: "ImageTk",
     node_draw: NodeDraw,
     type_enum,
     image_enum,
 ):
     logging.debug("update button(%s): %s", button, node_draw)
     self.hide_pickers()
     button.configure(image=image)
     button.image = image
     self.app.canvas.mode = GraphMode.NODE
     self.app.canvas.node_draw = node_draw
     if type_enum == NodeTypeEnum.NODE:
         self.node_enum = image_enum
     elif type_enum == NodeTypeEnum.NETWORK:
         self.network_enum = image_enum
示例#6
0
    def _add_button_to_frame_grid(
            cls,
            frame_and_name: FrameAndName,
            text: str,
            row: int,
            column: int,
            image: PhotoImage = None,
            padx: int = None,
            pady: int = None,
            sticky: GridPositionEnum = GridPositionEnum.NONE) -> Button:
        cls._debug(f'Add Button Grid [{text}] Row [{row}] Column [{column}]')

        button = Button(frame_and_name.frame, text=text, image=image)
        # Prevent GC delete image
        if image:
            button.image = image
        button.grid(row=row,
                    column=column,
                    sticky=sticky.value,
                    padx=padx,
                    pady=pady)
        return button
示例#7
0
    def setupUI(self):
        self.label_name = Label(self, text='Query:')
        self.label_name.grid(row=0, column=0, sticky='w')

        self.label_amount = Label(self, text='Per page:')
        self.label_amount.grid(row=1, column=0, sticky='w')

        self.label_page_number = Label(self, text='Page:')
        self.label_page_number.grid(row=2, column=0, sticky='w')

        label_save = Label(self, text='Save:')
        label_save.grid(row=3, column=0, sticky='w')

        label_quality = Label(self, text='Quality:')
        label_quality.grid(row=4, column=0, sticky='w')

        self.label_order_by = Label(self, text='Order by:')
        self.label_order_by.grid(row=5, column=0, sticky='w')

        label_random = Label(self, text='Random:')
        label_random.grid(row=6, column=0, sticky='w')

        self.var_name = StringVar()
        self.entry_name = Entry(self, textvariable=self.var_name)
        self.entry_name.grid(row=0, column=1, sticky='we')

        self.var_amount = IntVar()
        self.var_amount.set(10)
        self.entry_amount = Entry(self, textvariable=self.var_amount)
        self.entry_amount.grid(row=1, column=1, sticky='we')

        self.var_page_number = IntVar()
        self.var_page_number.set(1)
        self.entry_page_number = Entry(self, textvariable=self.var_page_number)
        self.entry_page_number.grid(row=2, column=1, sticky='we')

        self.var_folder_name = StringVar()
        entry_save = Entry(self, textvariable=self.var_folder_name)
        entry_save.grid(row=3, column=1, sticky='we')

        button_browse = Button(self, text='Browse', command=self.choice_folder)
        button_browse.grid(row=3, column=2, sticky='we')

        QUALITIES = {
            'Raw': 'raw',
            'Full': 'full',
            'Regular': 'regular',
            'Small': 'small',
            'Thumnail': 'thumb',
        }

        self.var_quality_rb = StringVar()
        group_quality_radiobutton = FrameGroupRadiobutton(
            self,
            side='left',
            variable=self.var_quality_rb,
            dict_option=QUALITIES,
            initialize='raw')
        group_quality_radiobutton.grid(row=4, column=1, sticky='w')

        ORDER_BY = {
            'Latest': 'latest',
            'Oldest': 'oldest',
            'Popular': 'popular',
        }

        self.var_order_by_rb = StringVar()
        self.group_order_by_radiobutton = FrameGroupRadiobutton(
            self,
            side='left',
            variable=self.var_order_by_rb,
            dict_option=ORDER_BY,
            initialize='latest')
        self.group_order_by_radiobutton.grid(row=5, column=1, sticky='w')

        self.var_random = IntVar()
        checkbutton_random = Checkbutton(
            self,
            variable=self.var_random,
            command=self.disable_order_by_for_random)
        checkbutton_random.grid(row=6, column=1, sticky='w')
        createToolTip(checkbutton_random, 'Max amount is 30')

        image_icon_download = PhotoImage(file='icon/down-arrow.png')
        button_download = Button(self,
                                 text='Download now!',
                                 image=image_icon_download,
                                 compound='left',
                                 command=self.check_paramenter_is_valid)
        button_download.image = image_icon_download
        button_download.grid(row=7, column=1)
示例#8
0
"""
Button with pictograms

use the mouse and press the button
creates second command window, could be to to with PhotoImage
"""

from tkinter import PhotoImage, Tk
from tkinter.ttk import Style, Button, Frame, Label

s = Style()
s.theme_use('default')
root = Tk()
# using alternative cross reference 'im1'
image1 = PhotoImage('im1', file='../images/close.gif')
image2 = PhotoImage(file='../images/close_active.gif')
image3 = PhotoImage(file='../images/close_pressed.gif')
fr = Frame()
fr.pack()
lab = Label(fr, text="Dont't forget to click and hover")
lab.pack(padx=4, pady=10)
# using alternative cross reference 'im1'
but = Button(fr,
             text='test',
             compound='right',
             image=('im1', 'pressed', image2, 'active', image3))
but.image = ('im1', 'pressed', image2, 'active', image3)
but.pack(padx=4, pady=10)

root.mainloop()
示例#9
0
    def initUI(self):
        self.master.title("meaning.ly")
        self.pack(fill=BOTH, expand=True)

        # File input
        frame_file = Frame(self)
        frame_file.pack(fill=X)

        lbl_file = Label(frame_file, text="File", width=9)
        lbl_file.pack(side=LEFT, padx=5, pady=5)

        photo = PhotoImage(file=r"assets/foldericon.png")
        photo2 = photo.subsample(25, 25)

        entry_file = tk.Entry(frame_file, highlightthickness=1)

        button_file = Button(frame_file,
                             image=photo2,
                             width=6,
                             command=lambda: self.browseFiles(entry_file))
        button_file.pack(side=RIGHT, padx=5, pady=5)
        button_file.image = photo2
        entry_file.pack(fill=X, padx=5, pady=5, expand=True)
        self.listOfEntries.append(entry_file)

        # List of phrases input
        frame_phrases = Frame(self)
        frame_phrases.pack(fill=X, expand=True)

        lbl_phrases = Message(frame_phrases, text="List of phrases", width=42)
        lbl_phrases.pack(side=LEFT, padx=(5, 9), pady=7)

        entry_phrases = tk.Text(frame_phrases, height=10, highlightthickness=1)
        entry_phrases.pack(fill=BOTH, padx=5, pady=7)
        self.listOfEntries.append(entry_phrases)

        # Options label
        frame_opt = Frame(self)
        frame_opt.pack(fill=X)

        lbl_opt = Label(frame_opt, text="Optional:", width=9)
        lbl_opt.pack(side=LEFT, padx=5, pady=5)

        # Threshold input
        frame_thresh = Frame(self)
        frame_thresh.pack(fill=X)

        lbl_thresh = Label(frame_thresh, text="Threshold", width=9)
        lbl_thresh.pack(side=LEFT, padx=(5, 5), pady=5)

        entry_thresh = tk.Entry(frame_thresh, highlightthickness=1)
        entry_thresh.pack(fill=X, padx=5, expand=True)
        self.listOfEntries.append(entry_thresh)

        # Symbol input
        frame_symbol = Frame(self)
        frame_symbol.pack(fill=X)

        lbl_symbol = Label(frame_symbol, text="Symbol", width=9)
        lbl_symbol.pack(side=LEFT, padx=(5, 5), pady=5)

        entry_symbol = tk.Entry(frame_symbol)
        entry_symbol.pack(fill=X, padx=5, expand=True)
        self.listOfEntries.append(entry_symbol)

        # Run & clear buttons
        frame_buttons = Frame(self)
        frame_buttons.pack(fill=X)

        button_help = Button(frame_buttons,
                             text='Help',
                             width=6,
                             command=popup_bonus)
        button_help.pack(side=LEFT, padx=5, pady=5)

        button_run = tk.Button(frame_buttons,
                               text='Run',
                               width=6,
                               bg='green',
                               command=lambda: self.run_encoding(button_run))
        button_run.pack(side=RIGHT, padx=5, pady=5)

        button_clear = Button(frame_buttons,
                              text='Clear',
                              width=6,
                              command=self.clear)
        button_clear.pack(side=RIGHT, padx=5, pady=5)