Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
INF-TC2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gayet Robin
INF-TC2
Commits
9d71cd31
Commit
9d71cd31
authored
4 years ago
by
Gayet Robin
Browse files
Options
Downloads
Patches
Plain Diff
Programmes du BE4
parent
0215c970
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
seance4_4h/Fichiers du BE/Exo1.py
+29
-0
29 additions, 0 deletions
seance4_4h/Fichiers du BE/Exo1.py
seance4_4h/Fichiers du BE/Exo3.py
+64
-0
64 additions, 0 deletions
seance4_4h/Fichiers du BE/Exo3.py
with
93 additions
and
0 deletions
seance4_4h/Fichiers du BE/Exo1.py
0 → 100644
+
29
−
0
View file @
9d71cd31
import
random
from
tkinter
import
*
def
tirage
():
nb
=
random
.
randint
(
1
,
100
)
texteResultat
.
set
(
'
Nombre :
'
+
str
(
nb
))
if
__name__
==
'
__main__
'
:
# création de l'arbre de scène
racine
=
Tk
()
# Appel à une méthode de classe (et non un constructeur, cf slide cours #2)
racine
.
title
(
'
Tirage aléatoire
'
)
racine
.
geometry
(
'
300x100+400+400
'
)
# Les widgets de la scène
boutonQuitter
=
Button
(
racine
,
text
=
'
Quitter
'
)
boutonQuitter
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
texteResultat
=
StringVar
()
labelResultat
=
Label
(
racine
,
textvariable
=
texteResultat
)
labelResultat
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
boutonLancer
=
Button
(
racine
,
text
=
'
Tirage
'
)
boutonLancer
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
# association des commandes aux widgets
boutonLancer
.
config
(
command
=
tirage
)
# appel dit callback (pas de parenthèses)
boutonQuitter
.
config
(
command
=
racine
.
destroy
)
# idem
racine
.
mainloop
()
# affichage de l'interface jusqu'à quit
\ No newline at end of file
This diff is collapsed.
Click to expand it.
seance4_4h/Fichiers du BE/Exo3.py
0 → 100644
+
64
−
0
View file @
9d71cd31
from
tkinter
import
*
from
formes
import
*
class
ZoneAffichage
(
Canvas
):
def
__init__
(
self
,
parent
,
largeur
,
hauteur
):
Canvas
.
__init__
(
self
,
parent
,
width
=
largeur
,
height
=
hauteur
)
self
.
formeActuelle
=
"
Rectangle
"
self
.
__ListeFormes
=
[]
def
ajout_forme
(
self
,
x
,
y
):
if
self
.
formeActuelle
==
'
Rectangle
'
:
self
.
__ListeFormes
.
append
(
Rectangle
(
self
,
x
-
5
,
y
-
10
,
10
,
20
,
'
brown
'
))
else
:
self
.
__ListeFormes
.
append
(
Ellipse
(
self
,
x
-
5
,
y
-
10
,
25
,
25
,
"
brown
"
))
def
delete_forme
(
self
,
x
,
y
):
for
f
in
self
.
__ListeFormes
:
if
f
.
contient_point
(
x
,
y
)
==
True
:
f
.
effacer
()
self
.
__ListeFormes
.
remove
(
1
)
break
def
selection_rectangle
(
self
):
self
.
formeActuelle
=
"
Rectangle
"
def
selection_ellipse
(
self
):
self
.
formeActuelle
=
"
Ellipse
"
class
FenPrincipale
(
Tk
):
def
__init__
(
self
):
Tk
.
__init__
(
self
)
self
.
configure
(
bg
=
'
grey
'
)
barreOutils
=
Frame
(
self
)
barreOutils
.
pack
(
side
=
TOP
)
boutonRectangle
=
Button
(
barreOutils
,
text
=
'
Rectangle
'
)
boutonRectangle
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
boutonEllipse
=
Button
(
barreOutils
,
text
=
'
Ellipse
'
)
boutonEllipse
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
boutonCouleur
=
Button
(
barreOutils
,
text
=
'
Couleur
'
)
boutonCouleur
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
boutonQuitter
=
Button
(
barreOutils
,
text
=
'
Quitter
'
)
boutonQuitter
.
pack
(
side
=
LEFT
,
padx
=
5
,
pady
=
5
)
self
.
__canevas
=
ZoneAffichage
(
self
,
600
,
400
)
self
.
__canevas
.
pack
(
side
=
TOP
,
padx
=
10
,
pady
=
10
)
self
.
__canevas
.
bind
(
"
<ButtonRelease-1>
"
,
self
.
release_canevas
)
boutonRectangle
.
config
(
command
=
self
.
__canevas
.
selection_rectangle
)
boutonEllipse
.
config
(
command
=
self
.
__canevas
.
selection_ellipse
)
self
.
__canevas
.
bind
(
"
<Control-ButtonRelease-1>
"
,
self
.
ctrlclick_canevas
)
def
release_canevas
(
self
,
event
):
self
.
__canevas
.
ajout_forme
(
event
.
x
,
event
.
y
)
def
ctrlclick_canevas
(
self
,
event
):
self
.
__canevas
.
delete_forme
(
event
.
x
,
event
.
y
)
if
__name__
==
"
__main__
"
:
fen
=
FenPrincipale
()
fen
.
mainloop
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment