Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5eb7091

Browse files
committed
adicionando novo exemplo
1 parent adbc01b commit 5eb7091

File tree

12 files changed

+228
-0
lines changed

12 files changed

+228
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from PIL import Image
2+
3+
img = Image.open('pythonImgIco.ico')
4+
img.show()
5+
6+
img.save('pythonImgIco.gif')
596 Bytes
Loading[フレーム]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from tkinter import *
2+
from tkinter.messagebox import showinfo
3+
4+
5+
def reply(name):
6+
showinfo(title='reply/resposta', message=f'hello, {name}\noi, {name}')
7+
8+
top = Tk()
9+
top.title('echo')
10+
11+
# ----------------------------------------
12+
# para funcionar imagem no windows
13+
# top.iconbitmap('pythonImgIco.ico')
14+
15+
# ----------------------------------------
16+
# linux
17+
img = PhotoImage('pythonImgIco.gif')
18+
top.call('wm', 'iconphoto', top._w, img)
19+
# ----------------------------------------
20+
21+
Label(top, text='enter your name:\nentre com teu nome:').pack(side=TOP)
22+
23+
entd = Entry(top)
24+
entd.pack(side=TOP)
25+
26+
bt = Button(top, text='submt\nenviar', command=lambda: reply(entd.get()))
27+
bt.pack(side=LEFT)
28+
29+
top.mainloop()
30+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from tkinter import *
2+
from tkinter.messagebox import showerror
3+
import shelve
4+
5+
6+
shelveName = 'class-shelve'
7+
fieldNames = ('name', 'age', 'pay')
8+
9+
def makeWidgets():
10+
global entries
11+
window = Tk()
12+
window.title('people shelve')
13+
form = Frame(window) # frame de window
14+
form.pack()
15+
16+
entries = {} # dicionario de entradas/entries
17+
18+
for (ix, label) in enumerate(('key', ) + fieldNames):
19+
lb = Label(form, text=label)
20+
entd = Entry(form)
21+
lb.grid(row=ix, column=0)
22+
entd.grid(row=ix, column=1)
23+
24+
Button(window, text='fetch', command=fetchRecord).pack(side=LEFT)
25+
Button(window, text='update', command=updateRecord ).pack(side=LEFT)
26+
Button(window, text='quit', command=window.quit).pack(side=RIGHT)
27+
return window
28+
29+
def fetchRecord():
30+
key = entries['key'].get()
31+
32+
try:
33+
record = db['key']
34+
except:
35+
showerror(title='error', message='no such key')
36+
else:
37+
for field in fieldNames:
38+
entries[field].delete(0, END)
39+
entries[field].insert(0, repr(getattr(record, field)))
40+
41+
42+
def updateRecord():
43+
key = entries['key'].get()
44+
45+
if key in db:
46+
record = db[key]
47+
48+
else:
49+
from person import Person
50+
record = Person(name='?', age='?')
51+
52+
for field in fieldNames:
53+
setattr(record, field, eval(entries[field].get()))
54+
db[key] = record
55+
db = shelve.open(shelveName)
56+
window = makeWidgets()
57+
window.mainloop()
58+
db.close()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Person:
2+
def __init__(self, name, age, pay=0, job=None):
3+
self.name = name
4+
self.age = age
5+
self.pay = pay
6+
self.job = job
7+
8+
# return ultimo nome
9+
def last_name(self):
10+
return self.name.split()[-1]
11+
12+
# dar aumento salarial
13+
def giveRaise(self, percent):
14+
self.pay *= float('1.' + str(percent))
15+
16+
if __name__ == '__main__':
17+
bob = Person('bob smith', 42, 3000, 'software')
18+
sue = Person('sue jones', 45, 4000, 'hardware')
19+
jonas = Person('jonas tes', 27, 1000, 'software')
20+
21+
print(sue.name)
22+
print(sue.pay)
23+
24+
sue.giveRaise(10)
25+
print(sue.pay)
26+
27+
print(bob.name)
28+
print(bob.job)
29+
30+
print(jonas.last_name())
31+
print(jonas.job)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import shelve
2+
3+
db = shelve.open('class-shelve')
4+
5+
for key in db:
6+
print(key, '->\n ', db[key].name, db[key].pay)
7+
8+
bob = db['bob']
9+
sue = db['sue']
10+
tom = db['tom']
11+
12+
print(bob.last_name())
13+
print(sue.last_name())
14+
print(tom.last_name())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /