apostila tkinter modulo c

Upload: eugenio-guimaraes-de-souza

Post on 07-Apr-2018

265 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Apostila Tkinter Modulo c

    1/61

    !!""####

    $%&'()'*&+)

    UNIVERSIDADE ESTADUAL PAULISTA

    JLIO DE MESQUITA FILHO

  • 8/4/2019 Apostila Tkinter Modulo c

    2/61

    2

    !"#$

    %$&'"#$! ()$* '$ ()$

    ! " # $%& '&((%&)*+! "

    '&((*,,+ " $%&

    '&((---%&.**+

    / * 0

    *12

    30!4.

    5**)0 !

    *"$%&230!

    156&'&((---*+

    6 & 1!

    7

    !&"18130

    4! 7! 8 " .9 2

    0*

    Josu Labaki

    #$%&

    /&:

    ;

  • 8/4/2019 Apostila Tkinter Modulo c

    3/61

    3

    +&,-

    !., /

    >*" ?

    @, A

    !$!&$! 0

    >B, C

    @- D

    E$-#;= >>

    !,&,1 2/

    > >?

    @F >G

    E* @>

    !3!4$&&!&$ 56

    >-% @E

    !3!7! 50

    > @G

    @5& @H

    E$8!:1 E>

    ? EA

    A#*) EH

    !3-'$,7$8 /9

    >) ?A

    @#;= ?G

    E*30 AI

    ?# A?

    !3:-;-,$ 9,4!!>!7!8 02

  • 8/4/2019 Apostila Tkinter Modulo c

    4/61

    4

    !.,

    ,$%&

    " & " 0

    1 ' =/5 1 "+!

    -230 *

    !*30

    *" $%& J- )" ,

    &$%&)"

    " , ' *37 51 30

    +

    2? '4!&$$$7$-!@'>A,$

  • 8/4/2019 Apostila Tkinter Modulo c

    5/61

    5

    -+ >L$*M

    &Q ' "*

    -+! &

  • 8/4/2019 Apostila Tkinter Modulo c

    6/61

    6

    4&K:&

    : %K#;=*

    2 ! 1!

    "#;=!!

    *0! & " 30 ! )* LM!

    *0X&*0LF&M

    1

    F*0X!)R*&,

    1@! " *7 K! 1K

    & )" 0 #;=! *8

    8*8,,&1*

    8P*8*)=/5

    "! 30 ,! =/5 *

    ""!

    ,=/5K!8

    ! 3 7

    S#;=

    !$!&$!

    2? ,!B',!!-.

    0-0!0

    #;= 8 ) -

    2

    No necessrio implementar os exemplos deste Mdulo. Todos eles esto disponveis para download a

    partir de http://labaki.tk.

  • 8/4/2019 Apostila Tkinter Modulo c

    7/61

    7

    & * 1 '

    +!.&"0

    */ #;= )

    &!"&!

    &LM'LM+''&+

    J1

    30.-

    "

    "1& ) .!

    *7&!*8!P)&"

    30-!

    30",

    !

  • 8/4/2019 Apostila Tkinter Modulo c

    8/61

    8

    5? -$C,$D,&1

    1"

    -($

  • 8/4/2019 Apostila Tkinter Modulo c

    9/61

    9

    )!*)

    $%& 0 ) 8! *

    10,

    30T*,U*0KT*,U!

    8*T*U

    - 37 30"

    $!*837*0

    self.botao['bg']='green'

    ;")&301

  • 8/4/2019 Apostila Tkinter Modulo c

    10/61

    10

    from Tkinter import *

    classJanela:

    def__init__(self,toplevel):

    self.fr1 = Frame(toplevel)

    self.fr1.pack()

    self.botao1 = Button(self.fr1,text='Oi!')

    self.botao1['background']='green'

    self.botao1['font']=('Verdana','12','italic','bold')

    self.botao1['height']=3

    self.botao1.pack()

    self.botao2 = Button(self.fr1,bg='red', font=('Times','16'))

    self.botao2['text']='Tchau!'

    self.botao2['fg']='yellow'

    self.botao2['width']=12

    self.botao2.pack()

    raiz=Tk()

    Janela(raiz)

    raiz.mainloop()

    '>!&$E

    P))&

    *7**0!P&>@"

    '*+! *0&!C*0

    &&>@!

    1 ! 30 LM

  • 8/4/2019 Apostila Tkinter Modulo c

    11/61

    11

    ! 3 37

    "*7 "! &2"*

    &)37!0

    6? $,-,$!&$D,&1!

    *130

    *7 Q 0 *

    )!

    = ) 1 -

    , K ! 5F

    '+! 6=#B'+!$ ' + '*1+!

    -

    -!3

    1 - " ! *

    ,

  • 8/4/2019 Apostila Tkinter Modulo c

    12/61

    12

    ! *0 L&9M ! !

    *1 *0

  • 8/4/2019 Apostila Tkinter Modulo c

    13/61

    13

    '>!&$E

    !R,'X$+*

    ! 0 0 & * 0

    $! 0 " 1

  • 8/4/2019 Apostila Tkinter Modulo c

    14/61

    14

    !,&,1

    O" & 0 37 1 " !

    &37

    4 * & $

    1,6-/

    2? 7$&$4$'

    LM

  • 8/4/2019 Apostila Tkinter Modulo c

    15/61

    15

    from Tkinter import *

    classJanela:

    def__init__(self,toplevel):

    self.frame=Frame(toplevel)

    self.frame.pack()

    self.texto=Label(self.frame, text='Clique para ficar amarelo')

    self.texto['width']=26

    self.texto['height']=3

    self.texto.pack()

    self.botaoverde=Button(self.frame,text='Clique')

    self.botaoverde['background']='green'

    self.botaoverde.bind("",self.muda_cor)

    self.botaoverde.pack()

    defmuda_cor(self, event):

    # Muda a cor do botao!

    if self.botaoverde['bg']=='green':

    self.botaoverde['bg']='yellow'

    self.texto['text']='Clique para ficar verde'

    else:

    self.botaoverde['bg']='green'

    self.texto['text']='Clique para ficar amarelo'

    raiz=Tk()

    Janela(raiz)

    raiz.mainloop()

    '>!&$E

  • 8/4/2019 Apostila Tkinter Modulo c

    16/61

    16

    ;*0&$+

    *0K

    ,*) *)

    *)37*

    370&!1

    *) ) ! *

    muda_cor(self, event)

    :$);!*0

    0*#;=2"!8

    :$1;!*0

    ** & )

    2

    self.botaoverde.bind(("",""), self.muda_cor)

    *0 *0

    *30

    - * 0 K

    *- F3 1

    ""*0Z

    'Z>!@E!*0

    + ""

    *-!"" -

  • 8/4/2019 Apostila Tkinter Modulo c

    17/61

    17

    5? F$-$7$&->!&$

    - "

    /&

    'J-1!1+2

    !":&

    ! K K &

    "

  • 8/4/2019 Apostila Tkinter Modulo c

    18/61

    18

    ;""

    5F! "" "

    P "" "ALFA" F !

    *""""

    B"$

  • 8/4/2019 Apostila Tkinter Modulo c

    19/61

    19

    # -*- coding: cp1252 -*-

    from Tkinter import *

    classJanela:

    def__init__(self,toplevel):

    self.frame=Frame(toplevel)

    self.frame.pack()

    self.frame2=Frame(toplevel)

    self.frame2.pack()

    self.titulo=Label(self.frame,text='VIDENTE2005',

    font=('Verdana','13','bold'))

    self.titulo.pack()

    self.msg=Label(self.frame,width=40,height=6,

    text = 'Adivinho o evento ocorrido!')

    self.msg.focus_force()

    self.msg.pack()

    # Definindo o boto 1

    self.b01=Button(self.frame2,text='Boto 1')

    self.b01['padx'],self.b01['pady'] = 10, 5

    self.b01['bg']='deepskyblue'

    self.b01.bind("",self.keypress01)

    self.b01.bind("",self.button01)

    self.b01.bind("",self.fin01)

    self.b01.bind("",self.fout01)

    self.b01['relief']=RIDGE

    self.b01.pack(side=LEFT)

    # Definindo o boto 2

    self.b02=Button(self.frame2,text='Boto 2')

    self.b02['padx'],self.b02['pady'] = 10, 5

    self.b02['bg']='deepskyblue'

    self.b02.bind("",self.keypress02)

    self.b02.bind("",self.button02)

    self.b02.bind("",self.fin02)

    self.b02.bind("",self.fout02)

    self.b02['relief']=RIDGE

    self.b02.pack(side=LEFT)

  • 8/4/2019 Apostila Tkinter Modulo c

    20/61

    20

    defkeypress01(self,event): self.msg['text']='ENTER sobre o Boto 1'

    defkeypress02(self,event): self.msg['text']='ENTER sobre o Boto 2'

    defbutton01(self,event): self.msg['text']='Clique sobre o Boto 1'

    defbutton02(self,event): self.msg['text']='Clique sobre o Boto 2'

    deffin01(self,event): self.b01['relief']=FLAT

    deffout01(self,event): self.b01['relief']=RIDGE

    deffin02(self,event): self.b02['relief']=FLAT

    deffout02(self,event): self.b02['relief']=RIDGE

    raiz=Tk()

    Janela(raiz)

    raiz.mainloop()

    '>!&$E

    * ! * $+ $ !

    !-P

    P:1*0

    !

    &>)!"&!*

  • 8/4/2019 Apostila Tkinter Modulo c

    21/61

    21

    30#;= '1 *1*0

    *0+305*.

    309

    6? $44!&@,&,1

    K&*:$);

    &!0"*0)1

    *0)"&&=

    *0-0,!*0

    &!""

    !!"!

    'K!LM*0

    +! 0 & "

    &!*/!

    &"**

    -30-!

    Widget(master, ...., command = self.event_handler)

  • 8/4/2019 Apostila Tkinter Modulo c

    22/61

    22

    from Tkinter import *

    classJanela:

    def__init__(self,toplevel):

    self.frame=Frame(toplevel)

    self.frame.pack()

    self.b1=Button(self.frame)

    self.b1.bind("", self.press_b1)

    self.b1.bind("", self.release_b1)

    self.b1['text'] = 'Clique em mim!'

    self.b1['width'], self.b1['bg'] = 20, 'brown'

    self.b1['fg']='yellow'

    self.b1.pack(side=LEFT)

    self.b2=Button(self.frame)

    self.b2['width'], self.b2['bg'] = 20, 'brown'

    self.b2['fg']='yellow'

    self.b2.pack(side=LEFT)

    self.b3=Button(self.frame, command=self.click_b3)

    self.b3['width'], self.b3['bg'] = 20, 'brown'

    self.b3['fg']='yellow'

    self.b3.pack(side=LEFT)

    defpress_b1(self,event):

    self.b1['text']=''

    self.b2['text']='Errou! Estou aqui!'

    defrelease_b1(self,event):

    self.b2['text']=''

    self.b3['text']='OOOpa! Mudei de novo!'

    defclick_b3(self):

    self.b3['text']='Ok... Voc me pegou...'

    instancia=Tk()

    Janela(instancia)

    instancia.mainloop()

  • 8/4/2019 Apostila Tkinter Modulo c

    23/61

    23

    '>!&$E

    *0&&)"&8

    *0"1*0)"

    2 *0 100

    *0"

    *0)

    !3!4$&!&$

    2? D,&1

    - 7 & " " 0 !

    1 & 30 -N K !

    %!*&

    %3730)"*7

    *!1'&+

    &!10!

    30 ,$1!show = '*'1*"!

    K""

    1 & &

    *&"

    30,&

  • 8/4/2019 Apostila Tkinter Modulo c

    24/61

    24

    *-'"*0

    +

    from Tkinter import *

    classPasswords:

    def__init__(self,toplevel):

    self.frame1=Frame(toplevel)

    self.frame1.pack()

    self.frame2=Frame(toplevel)

    self.frame2.pack()

    self.frame3=Frame(toplevel)

    self.frame3.pack()

    self.frame4=Frame(toplevel,pady=10)

    self.frame4.pack()

    Label(self.frame1,text='PASSWORDS', fg='darkblue',

    font=('Verdana','14','bold'), height=3).pack()

    fonte1=('Verdana','10','bold')

    Label(self.frame2,text='Nome: ',

    font=fonte1,width=8).pack(side=LEFT)

    self.nome=Entry(self.frame2,width=10,

    font=fonte1)

    self.nome.focus_force() # Para o foco comear neste campo

    self.nome.pack(side=LEFT)

    Label(self.frame3,text='Senha: ',

    font=fonte1,width=8).pack(side=LEFT)

    self.senha=Entry(self.frame3,width=10,show='*',

    font=fonte1)

    self.senha.pack(side=LEFT)

    self.confere=Button(self.frame4, font=fonte1, text='Conferir',

    bg='pink', command=self.conferir)

    self.confere.pack()

    self.msg=Label(self.frame4,font=fonte1,

  • 8/4/2019 Apostila Tkinter Modulo c

    25/61

    25

    height=3,text='AGUARDANDO...')

    self.msg.pack()

    defconferir(self):

    NOME=self.nome.get()

    SENHA=self.senha.get()

    if NOME == SENHA:

    self.msg['text']='ACESSOPERMITIDO'

    self.msg['fg']='darkgreen'

    else:

    self.msg['text']='ACESSONEGADO'

    self.msg['fg']='red'

    self.nome.focus_force()

    instancia=Tk()

    Passwords(instancia)

    instancia.mainloop()

    '>!&$E

    =3?4$8

  • 8/4/2019 Apostila Tkinter Modulo c

    26/61

    26

    !3!7!

    @-8"8& K 37! ! &!

    -! 37!

    $ =&

    & *) &! ! 8 8 S

    *),!&!

    !8!:1

    /. -

    3730*7*!

    11$30

    *-!1@$!K!K

    * -

    80A+$!!!5! $ 20GG37

    " - &

  • 8/4/2019 Apostila Tkinter Modulo c

    27/61

    27

    instancia=Tk()

    Kanvas(instancia)

    instancia.mainloop()

    '>!&$E

    3K:"*

    )S30K

    Y 0 ! 1"**30

    )!.*&

    2? $$&!&!

    !0

    =*&&

  • 8/4/2019 Apostila Tkinter Modulo c

    28/61

  • 8/4/2019 Apostila Tkinter Modulo c

    29/61

    29

    5? ,)!

    1&&

    self.nome_do_canvas.create_line(x1, y1, ...., xn, yn)

    &3'1>!%>+!'1@!%@+!'1E!%E+

    '1! %+

    !!)

    create_line(x1, y1, x2, y2, x3, y3, x4, y4, ......)

    create_line((x1, y1), (x2, y2), (x3, y3), (x4, y4), ......)

    create_line((x1, y1, x2, y2), (x3, y3, x4, y4), ......)!

    *=*&

    )"0)!&&

    $>X'1>!%>+$@X'1@!%@+!*K +-$>$@/2!

    8"3+-$>_I $>_> $@_I $@_> /

    aK&"!

    37300,!

    &!

  • 8/4/2019 Apostila Tkinter Modulo c

    30/61

    30

    from Tkinter import *

    classLinhas:

    def__init__(self,raiz):

    self.canvas = Canvas(raiz, width=400, height=400,

    cursor='watch', bd=5)

    self.canvas.pack()

    self.frame=Frame(raiz)

    self.frame.pack()

    self.last=[200,200]

    configs={'fg':'darkblue', 'bg':'ghostwhite', 'relief':GROOVE,

    'width':11,'font':('Verdana','8','bold')}

    self.b1=Button(self.frame, configs,

    text='Esquerda', command=self.left)

    self.b1.pack(side=LEFT)

    self.b2=Button(self.frame, configs,

    text='Paracima', command=self.up)

    self.b2.pack(side=LEFT)

    self.b3=Button(self.frame, configs,

    text='Parabaixo', command=self.down)

    self.b3.pack(side=LEFT)

    self.b4=Button(self.frame, configs,

    text='Direita', command=self.right)

    self.b4.pack(side=LEFT)

    defleft(self): # Desenha um segmento para a esquerda

    x, y = self.last[0]-10, self.last[1]

    self.canvas.create_line(self.last, x, y, fill='red')

    self.last=[x,y]

    defup(self): # Desenha um segmento para cima

    x, y = self.last[0], self.last[1]-10

    self.canvas.create_line(self.last, x, y, fill='yellow')

    self.last=[x,y]

    defdown(self): # Desenha um segmento para baixo

    x, y = self.last[0], self.last[1]+10

    self.canvas.create_line(self.last, x, y, fill='blue')

  • 8/4/2019 Apostila Tkinter Modulo c

    31/61

    31

    self.last=[x,y]

    defright(self): # Desenha um segmento para a direita

    x, y = self.last[0]+10, self.last[1]

    self.canvas.create_line(self.last, x, y, fill='purple')

    self.last=[x,y]

    instancia=Tk()

    Linhas(instancia)

    instancia.mainloop()

    '>!&$E#;=

    00=1

    ) & K

    ',+

    0"0.

    1;1

    6? $>;1$$HK1'>$:$

    /&8&&3

    &+&"

    3 & "

    8&8K&.

    30 2 &

    1!37$,

    6: 0 " & 2

    9+

    &37!, $*0

    8

  • 8/4/2019 Apostila Tkinter Modulo c

    32/61

    32

    $1*21

    self.nome_do_canvas.create_text(x, y)

    1!30 5!"'1!%+=

    1):!*1

    30 !

    :"*'1!%+/&X2J

    301'>II!>II+!*1

    "'>II!>II+0

  • 8/4/2019 Apostila Tkinter Modulo c

    33/61

    33

    " "&@II/!

    '>II!>I+"'>II!@II.>I+X'>II!>HI+!

    0 K &

    W @II * $

    '>II!$>I+!1

  • 8/4/2019 Apostila Tkinter Modulo c

    34/61

    34

    100, altura-10, fill='white')

    ret(15, altura-150, 185, altura-185, fill='black')

    pol(20, altura-140,

    95, altura-140,

    95, altura-30,

    20, altura-140, fill='red')

    pol(105, altura-30,

    105, altura-140,

    180, altura-140,

    105, altura-30, fill='black')

    self.canvas.create_text(100, altura-167.5, text='S P F C',

    font=('Arial','26','bold'),

    anchor=CENTER, fill='white')

    instancia=Tk()

    SPFC(instancia)

    instancia.mainloop()

    '>!&$E

    O" 0 0.9 2

    "&"!&0&

    300

  • 8/4/2019 Apostila Tkinter Modulo c

    35/61

    35

  • 8/4/2019 Apostila Tkinter Modulo c

    36/61

    36

    $ 30 ! 1 1

    .&"!&3

    &1!8XCI

    305!&8

    .&"!&"&P)

    115XHI)"&

    $ 4! &" 30

    6!B6/$=25='0+

    1 & 3

    *

    &!&*

    :6$

  • 8/4/2019 Apostila Tkinter Modulo c

    37/61

    37

    5 &! &

    # -*- coding: cp1252 -*-

    from Tkinter import *

    classFatias:

    def__init__(self,raiz):

    self.canvas=Canvas(raiz, width=200, height=200)

    self.canvas.pack()

    self.frame=Frame(raiz)

    self.frame.pack()

    self.altura = 200 # Altura do canvas

    self.canvas.create_oval(25, self.altura-25,

    175, self.altura-175,

    fill='deepskyblue', outline='darkblue')

    fonte=('Comic Sans MS', '14', 'bold')

    Label(self.frame, text='Fatia: ',

    font=fonte, fg='blue').pack(side=LEFT)

    self.porcentagem=Entry(self.frame, fg='red',

    font=fonte, width=5)

    self.porcentagem.focus_force()

    self.porcentagem.pack(side=LEFT)

    Label(self.frame, text='%',

    font=fonte, fg='blue').pack(side=LEFT)

    self.botao=Button(self.frame, text='Desenhar',

    command=self.cortar, font=fonte,

    fg='darkblue', bg='deepskyblue')

    self.botao.pack(side=LEFT)

    defcortar(self):

    arco=self.canvas.create_arc

    fatia=float(self.porcentagem.get())*359.9/100.

    arco(25, self.altura-25,

    175, self.altura-175,

  • 8/4/2019 Apostila Tkinter Modulo c

    38/61

    38

    fill='yellow', outline='red',

    extent=fatia)

    self.porcentagem.focus_force()

    instancia=Tk()

    Fatias(instancia)

    instancia.mainloop()

    '>!&$E

  • 8/4/2019 Apostila Tkinter Modulo c

    39/61

    39

    9? -,!4$&$@L$&$!7!

    *)!*=/

    4..*)&=/

    Q *) ! 7 &

    !=/*)01

    'L*,M+

    *) +-/=/*)-Z>!

    Z@!!Z/*)=/A)!A0!!A4

    K*=/!!L>M!L@M!

  • 8/4/2019 Apostila Tkinter Modulo c

    40/61

  • 8/4/2019 Apostila Tkinter Modulo c

    41/61

    41

    155, self.altura-85,

    182, self.altura-15, fill='dodgerblue')

    ret(45, self.altura-35,

    90, self.altura-60, fill='darkblue', outline='')

    ret(110, self.altura-35,

    155, self.altura-60, fill='darkblue', outline='')

    self.texto(100, self.altura-50, text=':',

    font=self.fonte, fill='yellow')

    # Fim do desenho do relgio-----------------------

    self.mostrar=Button(self.frame, text='Que horas so?',

    command=self.mostra,

    font=('Comic Sans MS', '11', 'bold'),

    fg='darkblue', bg='deepskyblue')

    self.mostrar.pack(side=LEFT)

    defmostra(self):

    self.canvas.delete('digitos_HORA')

    self.canvas.delete('digitos_MIN')

    HORA = str( localtime()[3] )

    MINUTO = str( localtime()[4] )

    self.texto(67.5, self.altura-50, text=HORA, fill='yellow',

    font=self.fonte, tag='digitos_HORA')

    self.texto(132.5, self.altura-50, text=MINUTO, fill='yellow',

    font=self.fonte, tag='digitos_MIN')

    instancia=Tk()

    Horas(instancia)

    instancia.mainloop()

  • 8/4/2019 Apostila Tkinter Modulo c

    42/61

    42

    '>!&$E

    Q &! " &

    ! 01 * $

    !'+1S&

    / ! K *)!

    &".!"8!:

    1&'#;=+

    !"B4$' 4$$$ $666=C$$

    D3 E ' !" $ C 6*4$3$5E4$

    3$3

    -*70*)

    &0=K

    &!0!.-

    "**!

    1!*)"

    _`

  • 8/4/2019 Apostila Tkinter Modulo c

    43/61

  • 8/4/2019 Apostila Tkinter Modulo c

    44/61

    44

    defesquerda(self, event): self.canvas.move('bola', -10, 0)

    defdireita(self, event): self.canvas.move('bola', 10, 0)

    defcima(self, event): self.canvas.move('bola', 0, -10)

    defbaixo(self, event): self.canvas.move('bola', 0, 10)

    instancia=Tk()

    Pacman(instancia)

    instancia.mainloop()

    '>!&$E

    30-

    &:-"

  • 8/4/2019 Apostila Tkinter Modulo c

    45/61

    45

    K"1*8

    !3-'$,7$

    P):,

    2? M$&$&!L!>!

    ).*3730$1!

    *

    *!)!!

    1K-

    B"K&)!5%-,GN"1GN"1/!&&

    "1)Y8!1!*0

    1K ) " *

    %-,GN8! GN8/ ) 0

    &7=4"

    )-$!

    %*8*:-&&&K)

    " 0 $ 1!

    %-,G$! G(/ )

    '-&+8"

    $ ! " 8 )!

    *8)

    K:

  • 8/4/2019 Apostila Tkinter Modulo c

    46/61

    46

    1 ) 0

    &"18

    & ) 0 ) 0

  • 8/4/2019 Apostila Tkinter Modulo c

    47/61

    47

    6)0)"

    &!*01K*89$!

    *01K)! &

    "1!EIIEII

    6 * 8 S 3

    &).Y.

    5? $>$,&$!

    1!&37

    ,"20-&!*!

    *,!!!%-!*-!,!!,!

    ! ,%* 'K +! * 'K

    LMV+ &-& '* + 1 * ,

    '+!'*!*+!

    ,,

    **H!,*HP

    "!,)

    6#&&!

    K 0 ) 4

    &1B""L=

    ,M23

    "#%02x%02x%02x" % (intens_vermelho, intens_verde, intens_azul)

    *"I

    @AA' #38c602+:

    ! - $ K

    *! * "1 '@AA! @AA! @AA+!

    8'I!I!I+

  • 8/4/2019 Apostila Tkinter Modulo c

    48/61

    48

    0 1 KW "

    *K*37*"&

    *30#;=

  • 8/4/2019 Apostila Tkinter Modulo c

    49/61

    49

    defmisturar(self):

    cor="#%02x%02x%02x" %(int(self.vermelho.get()),

    int(self.verde.get()),

    int(self.azul.get()))

    self.canvas.delete('bola')

    self.canvas.create_oval(15, 15, 185, 185,

    fill=cor, tag='bola')

    self.rgb['text'] = cor

    self.vermelho.focus_force()

    inst = Tk()

    Palheta(inst)

    inst.mainloop()

    '>!&$E

    2'+K.*0!KGIJK0L

    ($4$4$$$35>0MM$36

  • 8/4/2019 Apostila Tkinter Modulo c

    50/61

    50

    6? $4$&-$@,!$,"#$&$4$'

    - )

    3010

    :-04!

    -

    ,+5-/,+-/5

    30'

    ).+! )30300

    !,+5-/ ,+-/! 030

    30L&M*30"30

    !&

    2)@)30"2)

    x_absoluto = C1.winfo_pointerx()

    x_origem = C1.winfo_rootx()0!5+$N5+

    0

    $*3*30

    V20!)*"11

  • 8/4/2019 Apostila Tkinter Modulo c

    51/61

    51

    self.canvas.pack()

    defdesenhar(self,event):

    x_origem = self.canvas.winfo_rootx()

    y_origem = self.canvas.winfo_rooty()

    x_abs = self.canvas.winfo_pointerx()

    y_abs = self.canvas.winfo_pointery()

    try:

    P = (x_abs - x_origem, y_abs - y_origem)

    self.canvas.create_line(self.ultimo_P, P)

    self.ultimo_P = P

    except:

    self.ultimo_P=(x_abs - x_origem, y_abs - y_origem)

    inst = Tk()

    AutoCADE(inst)

    inst.mainloop()

    '>!&$E

  • 8/4/2019 Apostila Tkinter Modulo c

    52/61

    52

    !*)"

    1&+!)

    0'1!%+=/*)1'1!%+

    1130&K

    /K!"8*"

    +*&2&

    85!058>I

    Q)*!8'I!I!I+/

    " 8 K &W 8 "

    >I! I! @I ' &1 )"

    +

    # -*- coding: cp1252 -*-

    from Tkinter import *

    classPalheta2:

    def__init__(self,raiz):

    raiz.title('Palheta Grfica')

    self.canvas=Canvas(raiz, width=200, height=200)

    self.canvas.bind('', self.misturar)

    self.canvas.pack()

    bola = self.canvas.create_oval

    bola(20,180,70,130, fill='red', outline='')

    bola(75,180,125,130, fill='green', outline='')

    bola(130,180,180,130, fill='blue', outline='')

    bola(45, 120, 155, 10, fill='white',

    outline='', tag='bola')

    self.tom=[0,0,0]

    defmisturar(self,event):

    xo=self.canvas.winfo_rootx()

    yo=self.canvas.winfo_rooty()

    xa=self.canvas.winfo_pointerx()

    ya=self.canvas.winfo_pointery()

    cor=self.canvas.find_closest(xa-xo, ya-yo)[0]

    self.tom[cor-1] = self.tom[cor-1]+10

  • 8/4/2019 Apostila Tkinter Modulo c

    53/61

    53

    cor="#%02x%02x%02x" %(self.tom[0],

    self.tom[1],

    self.tom[2])

    self.canvas.delete('bola')

    self.canvas.create_oval(45, 120, 155, 10, fill=cor,

    outline='', tag='bola')

    inst = Tk()

    Palheta2(inst)

    inst.mainloop()

    '>!&$E

  • 8/4/2019 Apostila Tkinter Modulo c

    54/61

    54

    /? -,!&$&1$4,!

    Q #;= - &

    (&K!,0"Y

    *"K !

    , *

    -&-

    30"

    $,'&+$'+!

    -"$1!30,)6-$G),G)/

    ,06-$G) ,G0/ & - -> " &-@"

    - &" & -@$

    !"30,16-$G0,G0/-

    -E"&@!@

    ,)$K

    * ! $!

  • 8/4/2019 Apostila Tkinter Modulo c

    55/61

    55

    2 " X@!

    30-

    &!,!K-

    "&

    Q-"!.

    )330.

    37*1

    F!30 "- 0 13

    $ &K - S

    !30530

  • 8/4/2019 Apostila Tkinter Modulo c

    56/61

    56

    /) - !

    +-/ " , *

    +-/

  • 8/4/2019 Apostila Tkinter Modulo c

    57/61

  • 8/4/2019 Apostila Tkinter Modulo c

    58/61

    58

    !3J:-;-,$

    3718!!"

    &! 0 $ !

    30

    . *,f* 37 0

    "&((*,,

    F"/8

    61

    *"*!

    "

    #;=

    "P)

    ,$

    & 1 $& #" " *

    *" =

    8*

    FK1#;=

    !!1*30&!

    !F3"

    *!**!&"

    )& $ 8

    1* 37 F 30

    80)"8#;=9"

    K&$!*

    8!K&830

    8

  • 8/4/2019 Apostila Tkinter Modulo c

    59/61

    59

    &

    "*0&)LM!

    6*&""0&

    *)

    " " 30

    ")K

    K!*&5

    30 " 1*! P

    "30

    30&

    /&**7"&

    *))&:!8&!*

    "&1*)&$

    !&8

    &8!

    "

  • 8/4/2019 Apostila Tkinter Modulo c

    60/61

    60

    ) 5*. ) 1K

    39>E " $ )! *9

  • 8/4/2019 Apostila Tkinter Modulo c

    61/61