Show Menu
Cheatography

tkinter Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Einleitung

kurze Einleitung

öffnen eines Fensters

from tkinter import *

root=Tk() # öffnen eines Fenster
root.m­ain­loop()

Fenste­rgröße

root.g­eom­etr­y('­500­x500')
manuelles setzen der Fenste­rbreite und Höhe
root.a­ttr­ibu­tes­('-­ful­lsc­ree­n',­True)
Vollbild

Button

from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk



def next():
   print('weiter gehts')

root=Tk()
root.geometry('500x100')
#resizing the image
root.next = Image.open('next.png')
root.next = root.next.resize((40,40),Image.ANTIALIAS)
root.next=ImageTk.PhotoImage(root.next)

b1=ttk.Button(text='weiter_1',image=root.next,compound=BOTTOM, command=lambda:next()).pack(side=LEFT)
b2=ttk.Button(text='weiter_2',image=root.next,compound=TOP, command=lambda:next()).pack(side=LEFT)
b3=ttk.Button(text='weiter_3',image=root.next,compound=LEFT, command=lambda:next()).pack(side=LEFT)
b4=ttk.Button(text='weiter_4',image=root.next,compound=RIGHT, command=lambda:next()).pack(side=LEFT)
b5=ttk.Button(text='weiter_5',image=root.next,compound=NONE, command=lambda:next()).pack(side=LEFT)
b6=ttk.Button(text='weiter_6',image='',compound=BOTTOM, command=lambda:next()).pack(side=LEFT)

root.mainloop()

Button Bsp.