Example #1
0
 def insert_entry_field(self, txt, default=None, focus=False):
     frame = Frame(self.frame)
     frame.pack(fill="x")
     label = Label(frame, text=txt, width=6)
     label.pack(side="left", anchor="n", padx=5, pady=5)
     entry = Entry(frame)
     entry.pack(fill="x", padx=5, pady=5, expand=True)
     if default:
         entry.insert("end", default)
     if focus:
         entry.focus_force()
     self.entries["Entry"][txt] = entry
Example #2
0
 def insert_entry_field(self, txt, default=None, focus=False):
     frame = Frame(self.frame)
     frame.pack(fill="x")
     label = Label(frame, text=txt, width=6)
     label.pack(side="left", anchor="n", padx=5, pady=5)
     entry = Entry(frame)
     entry.pack(fill="x", padx=5, pady=5, expand=True)
     if default:
         entry.insert("end", default)
     if focus:
         entry.focus_force()
     self.entries["Entry"][txt] = entry
Example #3
0
class DateEntry(Frame):

    def __init__(self,
                 master=None,
                 dateformat='%B %d, %Y',
                 firstweekday=6,
                 startdate=None,
                 **kw
                 ):
        """
        Args:
            master (Widget): The parent widget.
            dateformat (str): The format string used to render the text in the entry widget. Default is '%B %d, %Y'.
            firstweekday (int): Specifies the first day of the week. ``0`` is Monday, ``6`` is Sunday (the default).
            startdate (datetime): The date to be in focus when the calendar is displayed. Current date is default.
            **kw: Optional keyword arguments to be passed to containing frame widget.
        """
        super().__init__(master=master, **kw)
        self.dateformat = dateformat
        self.firstweekday = firstweekday
        self.image = self.draw_button_image('white')
        self.startdate = startdate or datetime.today()

        # widget layout
        self.entry = Entry(self, name='date-entry')
        self.entry.pack(side='left', fill='x', expand='yes')
        self.button = ttk.Button(self, image=self.image, command=self.on_date_ask, padding=(2, 2))
        self.button.pack(side='left')

        # TODO consider adding data validation: https://www.geeksforgeeks.org/python-tkinter-validating-entry-widget/
        self.entry.insert('end', self.startdate.strftime(dateformat))  # starting entry value

    def draw_button_image(self, color):
        """Draw a calendar button image of the specified color

        Image reference: https://www.123rf.com/photo_117523637_stock-vector-modern-icon-calendar-button-applications.html

        Args:
            color (str): the color to draw the image foreground.

        Returns:
            PhotoImage: the image created for the calendar button.
        """
        im = Image.new('RGBA', (21, 22))
        draw = ImageDraw.Draw(im)

        # outline
        draw.rounded_rectangle([1, 3, 20, 21], radius=2, outline=color, width=1)

        # page spirals
        draw.rectangle([4, 1, 5, 5], fill=color)
        draw.rectangle([10, 1, 11, 5], fill=color)
        draw.rectangle([16, 1, 17, 5], fill=color)

        # row 1
        draw.rectangle([7, 9, 9, 11], fill=color)
        draw.rectangle([11, 9, 13, 11], fill=color)
        draw.rectangle([15, 9, 17, 11], fill=color)

        # row 2
        draw.rectangle([3, 13, 5, 15], fill=color)
        draw.rectangle([7, 13, 9, 15], fill=color)
        draw.rectangle([11, 13, 13, 15], fill=color)
        draw.rectangle([15, 13, 17, 15], fill=color)

        # row 3
        draw.rectangle([3, 17, 5, 19], fill=color)
        draw.rectangle([7, 17, 9, 19], fill=color)
        draw.rectangle([11, 17, 13, 19], fill=color)

        return ImageTk.PhotoImage(im)

    def on_date_ask(self):
        """A callback for when a date is requested from the widget button.
        
        Try to grab the initial date from the entry if possible. However, if this date is note valid, use the current
        date and print a message to the console.
        """
        try:
            self.startdate = datetime.strptime(self.entry.get(), self.dateformat)
        except Exception as e:
            print(e)
            self.startdate = datetime.today()
        olddate = datetime.strptime(self.entry.get() or self.startdate, self.dateformat)
        newdate = ask_date(self.entry, startdate=olddate, firstweekday=self.firstweekday)
        self.entry.delete('0', 'end')
        self.entry.insert('end', newdate.strftime(self.dateformat))
        self.entry.focus_force()
Example #4
0
def startUI():
    global root
    root = Tk()
    root.title("Serial Clicker")
    # root.geometry("400x400")
    # root.resizable(0,0)
    root.configure(bg="#333333")

    Label(root,
          text="Serial Clicker",
          font=('Helvetica', 20, 'bold'),
          bg="#333333",
          fg="white").pack(pady=5)
    frame = LabelFrame(root, bg="#1E1E1E", fg="white")
    frame.pack(side=TOP, padx=25, pady=10, ipadx=10, ipady=10)

    frame1 = Frame(frame, bg="#1E1E1E")
    frame2 = Frame(frame, bg="#1E1E1E")
    frame3 = Frame(frame, bg="#1E1E1E")
    frame1.pack(side=TOP, pady=7)
    frame2.pack(side=TOP, pady=7)
    frame3.pack(side=TOP, pady=7)

    v = StringVar()
    v.set("single")

    interval = Entry(frame1)
    healingtime = Entry(frame2)
    interval.focus_force()
    healingtime.focus_force()
    intervall = Label(frame1, text="Interval(in s) ", bg="#1E1E1E", fg="white")
    healingl = Label(frame2, text="Healing time", bg="#1E1E1E", fg="white")
    intervall.pack(side=LEFT, padx=3, pady=5, fill=X)
    interval.pack(side=LEFT, fill=X)
    healingl.pack(side=LEFT, padx=3, pady=5)
    healingtime.pack(side=LEFT)

    Radiobutton(frame3,
                text="Single",
                variable=v,
                value="single",
                bg="#1E1E1E",
                fg="white").pack(side=LEFT)
    Radiobutton(frame3,
                text="Double",
                variable=v,
                value="double",
                bg="#1E1E1E",
                fg="white").pack(side=LEFT)
    Radiobutton(frame3,
                text="Triple",
                variable=v,
                value="triple",
                bg="#1E1E1E",
                fg="white").pack(side=LEFT)

    try:
        button = Button(root,
                        text="Start",
                        bg="#1E1E1E",
                        fg="white",
                        width=10,
                        command=lambda: startCode(v.get(), int(interval.get()),
                                                  int(healingtime.get())))
        button.pack(side=BOTTOM, pady=10, ipadx=10, ipady=2)
    except:
        print("enter")
    root.mainloop()
Example #5
0
def startLogin():
    global root
    root = Tk()
    root.title("  Pass-Man Login")
    root.geometry("400x400")
    root.resizable(0, 0)
    root.configure(bg="white")
    root.iconphoto(True, PhotoImage(file=assetpath + 'padlock.png'))
    root.tk.call('tk', 'scaling', 1.6)

    style = Style()
    style.configure("TLabel", background="white")

    topf = Frame(root, bg="white")
    topf.pack(pady=20, side=TOP)

    Label(topf, text="Pass-Man", font=("Helvetica", 18, 'bold'),
          bg="white").grid(row=0, column=4)
    Label(topf, text="Password manager", font=("Helvetica", 8),
          bg="white").grid(row=1, column=4)
    img = ImageTk.PhotoImage(
        Image.open(assetpath + "padlock.png").resize((40, 40)))
    Label(topf, image=img, bg="white").grid(row=0, column=2, rowspan=2, padx=8)

    # Separator(root,orient=HORIZONTAL).pack()
    # divider=ImageTk.PhotoImage(Image.open(assetpath+"divider.png").resize((300,20)))
    # Label(root,image=divider,bg="green").pack()

    detailf = Frame(root, bg="white")
    detailf.pack(pady=25, side=TOP)

    useri = ImageTk.PhotoImage(
        Image.open(assetpath + "login.png").resize((30, 30)))
    Label(detailf, image=useri, bg="white").grid(row=0, column=2, padx=10)
    keyi = ImageTk.PhotoImage(
        Image.open(assetpath + "key.png").resize((30, 30)))
    Label(detailf, image=keyi, bg="white").grid(row=1, column=2, padx=10)
    user = Entry(detailf)
    pwd = Entry(detailf, show="*")
    user.grid(row=0, column=3, columnspan=4)
    pwd.grid(row=1, column=3, columnspan=4)
    # user.insert(0,'Username')
    # pwd.insert(0,'Password')
    user.focus_force()
    pwd.focus_force()

    #submit area starts
    submitf = Frame(root, bg="white")
    submitf.pack(side=TOP, pady=(25, 6))

    logini = ImageTk.PhotoImage(
        Image.open(assetpath + "tick.png").resize((30, 30)))
    loginb = Button(submitf,
                    text=" Login",
                    image=logini,
                    compound=LEFT,
                    bg="white",
                    bd=0,
                    activebackground="white",
                    command=lambda: login(user.get(), pwd.get()))
    loginb.pack(side=LEFT, padx=10)

    canceli = ImageTk.PhotoImage(
        Image.open(assetpath + "cancel.png").resize((30, 30)))
    cancelb = Button(submitf,
                     text=" Cancel",
                     image=canceli,
                     compound=LEFT,
                     bg="white",
                     bd=0,
                     activebackground="white",
                     command=exitLogin)
    cancelb.pack(side=LEFT, padx=10)

    #bottom frames
    bottomf = Frame(root, bg="white")
    bottomf.pack(pady=20)
    b1f = Frame(bottomf, bg="white")
    b1f.pack(side=TOP, pady=0)
    b2f = Frame(bottomf, bg="white")
    b2f.pack(side=TOP, pady=0)
    Label(b1f, text="Don't have an account?", bg="white").pack(side=LEFT)
    Button(b1f,
           text="Sign up",
           fg="dodger blue",
           bg="white",
           bd=0,
           activebackground="white",
           activeforeground="dodger blue",
           command=startSignup).pack(side=LEFT, pady=0, ipady=0)
    Button(b2f,
           text="Forgot your password?",
           fg="dodger blue",
           bg="white",
           bd=0,
           activebackground="white",
           activeforeground="dodger blue",
           command=startForget).pack(pady=0, ipady=0)

    root.mainloop()
Example #6
0
class DateEntry(Frame):
    """A date entry widget that combines a ``ttk.Combobox`` and a ttk.Button`` with a callback attached to the
    ``ask_date`` function.

    When pressed, displays a date chooser popup and then inserts the returned value into the combobox.

    Optionally set the ``startdate`` of the date chooser popup by typing in a date that is consistent with the format
    that you have specified with the ``dateformat`` parameter. By default this is `%Y-%m-%d`.

    Change the style of the widget by using the `TCalendar` style, with the colors: 'primary', 'secondary',
    'success', 'info', 'warning', 'danger'. By default, the `primary.TCalendar` style is applied.

    Change the starting weekday with the ``firstweekday`` parameter for geographies that do not start the week
    on `Sunday`, which is the widget default.
    """
    def __init__(self,
                 master=None,
                 dateformat='%Y-%m-%d',
                 firstweekday=6,
                 startdate=None,
                 style='TCalendar',
                 **kw):
        """
        Args:
            master (Widget): The parent widget.
            dateformat (str): The format string used to render the text in the entry widget. Default is '%Y-%m-%d'. For
                more information on date formats, see the python documentation or https://strftime.org/.
            firstweekday (int): Specifies the first day of the week. ``0`` is Monday, ``6`` is Sunday (the default).
            startdate (datetime): The date to be in focus when the calendar is displayed. Current date is default.
            **kw: Optional keyword arguments to be passed to containing frame widget.
        """
        super().__init__(master=master, **kw)
        self.dateformat = dateformat
        self.firstweekday = firstweekday
        self.startdate = startdate or datetime.today()
        self.base_style = style

        # entry widget
        entry_style, button_style = self.generate_widget_styles()
        self.entry = Entry(self, name='date-entry', style=entry_style)
        self.entry.pack(side='left', fill='x', expand='yes')

        # calendar button
        image_color = self.tk.call("ttk::style", "lookup", button_style,
                                   '-%s' % 'foreground', None, None)
        if 'system' in image_color.lower():
            self.image = self.draw_button_image(
                self.convert_system_color(image_color))
        else:
            self.image = self.draw_button_image(image_color)
        self.button = ttk.Button(self,
                                 image=self.image,
                                 command=self.on_date_ask,
                                 padding=(2, 2),
                                 style=button_style)
        self.button.pack(side='left')

        # TODO consider adding data validation: https://www.geeksforgeeks.org/python-tkinter-validating-entry-widget/
        self.entry.insert(
            'end', self.startdate.strftime(dateformat))  # starting entry value

    def convert_system_color(self, systemcolorname):
        """Convert a system color name to a hexadecimal value

        Args:
            systemcolorname (str): a system color name, such as `SystemButtonFace`
        """
        r, g, b = [x >> 8 for x in self.winfo_rgb(systemcolorname)]
        return f'#{r:02x}{g:02x}{b:02x}'

    def draw_button_image(self, color):
        """Draw a calendar button image of the specified color

        Image reference: https://www.123rf.com/photo_117523637_stock-vector-modern-icon-calendar-button-applications.html

        Args:
            color (str): the color to draw the image foreground.

        Returns:
            PhotoImage: the image created for the calendar button.
        """
        im = Image.new('RGBA', (21, 22))
        draw = ImageDraw.Draw(im)

        # outline
        draw.rounded_rectangle([1, 3, 20, 21],
                               radius=2,
                               outline=color,
                               width=1)

        # page spirals
        draw.rectangle([4, 1, 5, 5], fill=color)
        draw.rectangle([10, 1, 11, 5], fill=color)
        draw.rectangle([16, 1, 17, 5], fill=color)

        # row 1
        draw.rectangle([7, 9, 9, 11], fill=color)
        draw.rectangle([11, 9, 13, 11], fill=color)
        draw.rectangle([15, 9, 17, 11], fill=color)

        # row 2
        draw.rectangle([3, 13, 5, 15], fill=color)
        draw.rectangle([7, 13, 9, 15], fill=color)
        draw.rectangle([11, 13, 13, 15], fill=color)
        draw.rectangle([15, 13, 17, 15], fill=color)

        # row 3
        draw.rectangle([3, 17, 5, 19], fill=color)
        draw.rectangle([7, 17, 9, 19], fill=color)
        draw.rectangle([11, 17, 13, 19], fill=color)

        return ImageTk.PhotoImage(im)

    def generate_widget_styles(self):
        """Generate all the styles required for this widget from the ``base_style``.

        Returns:
            Tuple[str]: the styles to be used for entry and button widgets.
        """
        match = re.search(COLOR_PATTERN, self.base_style)
        color = '' if not match else match.group(0) + '.'
        entry_style = f'{color}TEntry'
        button_style = f'{color}TButton'
        return entry_style, button_style

    def on_date_ask(self):
        """A callback for the date push button.
        
        Try to grab the initial date from the entry if possible. However, if this date is not valid, use the current
        date and print a warning message to the console.
        """
        try:
            self.startdate = datetime.strptime(self.entry.get(),
                                               self.dateformat)
        except Exception as e:
            print(e)
            self.startdate = datetime.today()
        olddate = datetime.strptime(self.entry.get() or self.startdate,
                                    self.dateformat)
        newdate = ask_date(self.entry,
                           startdate=olddate,
                           firstweekday=self.firstweekday,
                           style=self.base_style)
        self.entry.delete('0', 'end')
        self.entry.insert('end', newdate.strftime(self.dateformat))
        self.entry.focus_force()