فهرست منبع

Use entry_point in all examples

Thomas Kluyver 11 سال پیش
والد
کامیت
f20aaf7271
5فایلهای تغییر یافته به همراه42 افزوده شده و 34 حذف شده
  1. 21 20
      examples/console/guessnumber.py
  2. 4 1
      examples/console/installer.cfg
  3. 0 12
      examples/tkinter/example.py
  4. 13 0
      examples/tkinter/exampleapp.py
  5. 4 1
      examples/tkinter/installer.cfg

+ 21 - 20
examples/console/guessnumber.py

@@ -2,26 +2,27 @@
 
 import random
 
-number = random.randint(1, 100)
-guesses = 0
+def main()
+    number = random.randint(1, 100)
+    guesses = 0
 
-print("I'm thinking of a number, between 1 and 100. Can you guess what it is?")
-while True:
-    guesses += 1
-    guess = input('= ')
-    try:
-        guess = int(guess)
-    except ValueError:
-        print("Base 10 integers only, please.")
-        continue
+    print("I'm thinking of a number, between 1 and 100. Can you guess what it is?")
+    while True:
+        guesses += 1
+        guess = input('= ')
+        try:
+            guess = int(guess)
+        except ValueError:
+            print("Base 10 integers only, please.")
+            continue
 
-    if guess > number:
-        print("Too high!")
-    elif guess <  number:
-        print("Too low!")
-    else:
-        print("That's right, {}. You got it in {} guesses.".format(number, guesses))
-        break
+        if guess > number:
+            print("Too high!")
+        elif guess <  number:
+            print("Too low!")
+        else:
+            print("That's right, {}. You got it in {} guesses.".format(number, guesses))
+            break
 
-print()
-input("Press enter to quit.")
+    print()
+    input("Press enter to quit.")

+ 4 - 1
examples/console/installer.cfg

@@ -1,9 +1,12 @@
 [Application]
 name=Guess the Number
 version=1.0
-script=guessnumber.py
+entry_point=guessnumber:main
 # We need to set this to get a console:
 console=true
 
 [Python]
 version=3.4.0
+
+[Include]
+packages=guessnumber

+ 0 - 12
examples/tkinter/example.py

@@ -1,12 +0,0 @@
-from tkinter import *
-
-root = Tk()
-root.title("Python Example App")
-t = Text(root)
-t.insert(END, "Type stuff here.")
-t.pack()
-
-w = Label(root, text="Hello, world!")
-w.pack()
-
-root.mainloop()

+ 13 - 0
examples/tkinter/exampleapp.py

@@ -0,0 +1,13 @@
+from tkinter import *
+
+def main():
+    root = Tk()
+    root.title("Python Example App")
+    t = Text(root)
+    t.insert(END, "Type stuff here.")
+    t.pack()
+
+    w = Label(root, text="Hello, world!")
+    w.pack()
+
+    root.mainloop()

+ 4 - 1
examples/tkinter/installer.cfg

@@ -1,7 +1,10 @@
 [Application]
 name=My App
 version=1.0
-script=example.py
+entry_point=exampleapp:main
 
 [Python]
 version=3.4.0
+
+[Include]
+packages=exampleapp