0% found this document useful (0 votes)
5 views3 pages

Python Turtle and Tkinter Examples

The document contains multiple Python code snippets demonstrating various functionalities, including drawing circles with the turtle module, file handling with the os module, and creating graphical user interfaces using tkinter. It showcases button creation, event handling, and styling with ttk, as well as layout management using grid. Each section provides practical examples for users to understand the respective concepts.

Uploaded by

mouadelmesaoudi1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Turtle and Tkinter Examples

The document contains multiple Python code snippets demonstrating various functionalities, including drawing circles with the turtle module, file handling with the os module, and creating graphical user interfaces using tkinter. It showcases button creation, event handling, and styling with ttk, as well as layout management using grid. Each section provides practical examples for users to understand the respective concepts.

Uploaded by

mouadelmesaoudi1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

==========================================================================>

[ circle with python ]

import turtle

t = [Link]()
s = [Link]()
[Link]("black")
[Link](2)
[Link](10)
for i in range(15) :
for col in ("red" , "magenta" , "blue" , "cyan" , "green" , "yellow") :
[Link](col)
[Link](150)
[Link](10)
[Link]()

=========================================================================>

[ files_code ]

import os
# the place where the computer sherche or greated when we write [file = open("name
of the file" , "the mode 'r' 'a' ...")] : Main Current working directory
print([Link]())
print("="*50)
# give as the folder where [Link] exist[c:\Users\HP\Desktop\python_file]
print([Link]([Link](__file__)))
#print("="*50)
# give as [Link] link in our computer
[c:/Users/HP/Desktop/python_file/[Link]]
#print([Link](__file__))
print("="*50)
# change current working directory
[Link]([Link]([Link](__file__)))
print([Link]())
print("="*50)
file = open("[Link]" )

==========================================================================>

[ tkinter ]

from tkinter import *


from tkinter import ttk # ttk is a class were we find some fonction like Button
root = Tk()
button = [Link](root , text = "haha")
[Link]()# set the button in the window
def butt_clik() :
print("the button is clik")

[Link](command = butt_clik)# when the user click the button do the command
[Link]()# the programme click the button and do the command
[Link](["disabled"]) # block the button
[Link](["!disabled"]) # line 12 !
[Link](["disabled"])

[Link]()

--------------------------------------------------------------------------

from tkinter import *


from tkinter import ttk
screen = Tk()
photo = PhotoImage(file = r"C:\Users\HP\Pictures\Camera Roll\[Link]") #add a
photo in a vrb
the_photo_after_update = [Link](20,20) # with subsample we update the
photo size
entry = Entry(screen , width=60 , bg = "light blue")
[Link]()
button = [Link](screen , text = "get")
[Link](image=the_photo_after_update , compound= LEFT) # put the photo in the
button [compound set the position of the photo ]
[Link]()
def get_info() :
the_info = [Link]()
print(the_info)
[Link](0 ,END)

[Link](command = get_info)

[Link]()

--------------------------------------------------------------------------

bind("<>",fonction_name) : do the role of the fonctions listen() and keypress('',)


ex : [Link]("<ButtonPress>" , clik_button)

-------------------------------------------------------------------------

[ the style ]

from tkinter import *


from tkinter import ttk

root = Tk()
[Link]("style")
b1 = [Link](root , text = "clik" )
b2 = [Link](root , text = "clik" )
b3 = [Link](root , text = "clik" )
[Link]()
[Link]()
[Link]()
style = [Link]()# now the vrb style is the Style
the_them = style.theme_use()# we put the name of the theme used in the vrb
the_them
print(the_them)# we print the theme name
the_theme_exist = style.theme_names()# we put the names of the themes exist in the
vrb the_theme_exist
print(the_theme_exist)#we print the themes names
style.theme_use("clam")# we change the theme
# with default all the button are exist in the class 'TButton' than ween we change
the Button style all the button form change
the_class_name = b1.winfo_class()#we cheke b1 class
print(the_class_name)
[Link]("TButton" ,foreground = "grey")#we change the text color
[Link]("TButton" ,background = "red" , font = ("Arail" , 18 , "bold"))
[Link]("new_class.TButton" , font = ("Arail" , 30 , "bold")) # we put
'TButton' propreties in 'new_class' and we edit the font
[Link](style="new_class.TButton")# we set the new style how exist in the new
class to the button b1

[Link]()

-------------------------------------------------------------------------

[ grid fonction and style ]

from tkinter import *


from tkinter import ttk
root = Tk()
[Link](root ,background="light blue" , text="label one",font=("Arial" , 18 ,
"normal")).grid(row=0 , column=0 , sticky="snew")
[Link](root ,background="grey" , text="label tow",font=("Arial" , 18 , "normal")
).grid(row=0 , column=1 , sticky="snew")
[Link](root ,background="red" , text="label tree" , font=("Arial" , 18 ,
"normal") ).grid(row=1 , column=0 ,columnspan=2 , sticky="snew")
[Link](root ,background="green" , text="label fore" , font=("Arial" , 18 ,
"normal") , ).grid(row=0 , column=2 ,rowspan=2 , sticky="snew")
[Link](0,weight=1)
[Link](1,weight=1)
[Link](0,weight=1)
[Link](1,weight=1)
[Link](2,weight=1)

[Link]()

You might also like