Answers for "tkinter python3"

13

tkinter python 3

import tkinter as tk

obj = tk.Tk() # Creates a tkinter object
label = tk.Label(obj, text="This is a text button")
Posted by: Guest on February-01-2020
1

tkinter python

from tkinter import *
import time, datetime
from time import gmtime, strftime

root = Tk()

# Window Attributes
root.overrideredirect(1)
root.wm_attributes("-transparentcolor", "gray99")

running = True

# close window
def close(event):
    global running
    running = False

root.bind('<Escape>', close)

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

timeframe = Frame(root, width=screen_width, height=screen_height, bg="gray99")
timeframe.grid(row=0,column=0)

tkintertime = StringVar()
timelabel = Label(timeframe, textvariable=tkintertime, fg="white", bg="gray99", font=("NovaMono", 40))
timelabel.place(y=screen_height/2 - 60, x=screen_width/2, anchor="center")

tkinterdate = StringVar()
datelabel = Label(timeframe, textvariable=tkinterdate, fg="white", bg="gray99", font=("Bahnschrift", 15))
datelabel.place(y=screen_height/2 + 60, x=screen_width/2, anchor="center")


while running:
    tkintertime.set(value=strftime("%H:%M:%S"))
    tkinterdate.set(value=strftime("%A, %e %B"))
    root.update_idletasks()
    root.update()
    time.sleep(1)
Posted by: Guest on August-07-2021
-2

tkinter python3

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()
Posted by: Guest on March-11-2021

Python Answers by Framework

Browse Popular Code Answers by Language