from tkinter import *
import ttk # pip install pyttk
root = Tk()
variable = StringVar(root)
variable.set("Your choise")
combobox = ttk.Combobox(root, textvariable=variable, values=[*[f'Your number is {i}' for i in range(1,7)]*20])
combobox.pack()
root.mainloop()
from tkinter import *
from time import sleep
class Myfunctions(object):
def __init__(self, window):
self.window = window
def send_email(self):
self.window.title('Sending message..')
sleep(2)
self.window.title('OK')
def send_email_with_error(self):
try:
10/0
except Exception as e:
self.window.title('Error sending: '+ str(e))
window = Tk()
helper = Myfunctions(window)
def on():
helper.send_email()
def off():
helper.send_email_with_error()
on_btn = Button(window,text='on', height=1, width=20, command=lambda:on()).pack()
off_btn = Button(window,text='off', height=1, width=20, command=lambda:off()).pack()
window.geometry('400x50')
window.resizable(width=False, height=False)
window.mainloop()
from tkinter import *
def get_text():
s = text.get(1.0, END)
print(s)
root = Tk()
text = Text(width=25, height=5)
text.pack()
Button(root, text="В консоль->",
command=get_text).pack(side=LEFT)
root.mainloop()
from tkinter import *
import turtle as t
import time
import threading
class cat():
def __init__(self, кольор, прикраси_набор, прикраси):
global root
root = Tk()
root.iconbitmap(r"C:\\cat.ico")
root.resizable(0, 0)
root.title("cat home")
root.geometry("600x470")
print(root.winfo_rooty()+(270-root.winfo_rooty()))
w = Canvas(root, width=root.winfo_rootx()+(600-root.winfo_rootx()), \
height=root.winfo_rooty()+(470-root.winfo_rooty()))
w.grid()
self.windows = w
self.red = t.TurtleScreen(self.windows)
світ_image = r"C:\\спрайти\\кіт\\світ2.gif"
self.red.addshape(світ_image)
self.світ = t.RawTurtle(self.red)
self.світ.shape(світ_image)
self.світ.up()
self.color = кольор
self.прикраси = прикраси
self.image = (r"C:\\спрайти\\кіт\\кіт %s.gif" % кольор)
print(self.image)
self.id = t.RawTurtle(self.red)
self.red.addshape(self.image)
self.id.shape(self.image)
self.id.up()
self.id.speed(2)
print(str(len(self.прикраси)+1) + str(self.прикраси))
for r in range(0, len(self.прикраси)):
self.прикраси[r] = t.RawTurtle(self.red)
self.прикраси[r].speed(100)
self.image_прикраса = (r"C:\\спрайти\\кіт\\прикраса %s.gif" % прикраси_набор[r])
self.red.addshape(self.image_прикраса)
self.прикраси[r].shape(self.image_прикраса)
self.прикраси[r].up()
if прикраси_набор[r] == "бант":
self.прикраси[r].left(-90)
self.прикраси[r].forward(10)
self.прикраси[r].left(90)
self.прикраси[r].forward(13)
self.прикраси[r].speed(2)
self.id.setheading(90)
self.id.forward(-10)
self.id.setheading(-90)
self.прикраси[r].setheading(-90)
self.x = 0
self.y = 0
self.start_action()
def loop_poop(self):
while True:
print(time.ctime())
time.sleep(1)
def start_action(self):
thread = threading.Thread(target=self.loop_poop)
thread.start()
def Left(self, evt):
try:
up = -35
self.x -= 35
self.світ.forward(up)
except RecursionError:
pass
def right(self, evt):
try:
up = 35
self.x += up
self.світ.forward(up)
except RecursionError:
pass
def jump(self, evt):
up = 18
self.y += up
self.id.forward(0-up)
for r in range(0, len(self.прикраси)):
self.прикраси[r].forward(0-up)
time.sleep(0.6)
self.id.forward(up)
for r in range(0, len(self.прикраси)):
self.прикраси[r].forward(up)
self.y -= up
red = cat("рудий", ["бант"], [1])
global root
root.bind('<Right>', red.Left)
root.bind('<Left>', red.right)
root.bind('<Up>', red.jump)
root.mainloop()
from tkinter import *
import time
import os
root = Tk()
frameCnt = 12
frames = [PhotoImage(file='1.gif',format = 'gif -index %i' %(i)) for i in range(frameCnt)]
def update(ind):
frame = frames[ind]
ind += 1
if ind == frameCnt:
ind = 0
label.configure(image=frame)
root.after(100, update, ind)
label = Label(root)
label.pack()
root.after(0, update, 0)
root.mainloop()