Senin, 10 November 2014

Tkinter Example for make Loading...

Label, Button, and Scale Demo (tkhello4.py)
Our final introductory widget example introduces the Scale widget and highlights how widgets can "communicate" with each other using callbacks [such as resize()]. The text in the Label widget is affected by actions taken on the Scale widget.
1  #!/usr/bin/env python
2
3  from Tkinter import *
4
5  def resize(ev=None):
6      label.config(font='Helvetica -%d bold' % \
7          scale.get())
8
9  top = Tk()
10 top.geometry('250x150')
11
12 label = Label(top, text='Hello World!',
13     font='Helvetica -12 bold')
14 label.pack(fill=Y, expand=1)
15
16 scale = Scale(top, from_=10, to=40,
17     orient=HORIZONTAL, command=resize)
18 scale.set(12)
19 scale.pack(fill=X, expand=1)
20
21 quit = Button(top, text='QUIT',
22     command=top.quit, activeforeground='white',
23     activebackground='red')
24 quit.pack()
25
26 mainloop()
New features of this script include a resize() callback function (lines 5-7), which is attached to the Scale. This is the code that is activated when the slider on the Scale is moved, resizing the size of the text in the Label.
We also define the size (250 x 150) of the top-level window (line 10). The final difference between this script and the first three is that we import the attributes from the Tkinter module into our namespace with "from Tkinter import *." Although not recommended because it "pollutes" your namespace, we do it here mainly because this application involves a great number of references to Tkinter attributes. This would require use of their fully qualified names for each and every attribute access. By using the undesired shortcut, we are able to access attributes with less typing and have code that is easier to read, at some cost.
As you can see from Figure 19-4, both the slider mechanism as well as the current set value show up in the main part of the window. Figure 19-4 shows the state of the GUI after the user moves the scale/slider to avalue of 36.
Figure 19-4. Tkinter Label, Button, and Scale widgets (tkhello4.py)

As you can see from the code, the initial setting for the scale when the application starts is 12 (line 18).

Related Posts:

  • Belajar Matematika Diskrit kelas Teknik Informatika Matematika diskrit atau diskret adalah cabang matematika yang membahas segala sesuatu yang bersifat diskrit. Diskrit disini artinya tidak saling berhubungan (lawan dari kontinyu). Objek yang dibah… Read More
  • Pengenalan Teknik Informatika Apa Itu Teknik Informatika ? Teknik Informatika merupakan kumpulan disiplin ilmu dan teknik yang secara khusus menangani masalah transformasi atau pengolahan data dengan memanfaatkan se-optimal mungkin teknologi… Read More
  • PERANGKAT LUNAK APLIKASI PERANGKAT LUNAK APLIKASI Perangkat lunak aplikasi merupakan perangkat lunak yang biasa digunakan oleh siapa saja untuk membantu pekerjaannya. Perangkat lunak aplikasi dapat dengan mudah di install di dalam komputer kita… Read More
  • Mulai Menggunakan Python Python bisa diinstal di berbagai sistem operasi termasuk windows, Mac OS X, OS/2 atau Linux/UNIX. Tapi jika anda memakai MAc OS X atau Linux, Anda akan mendapatkan python secara default. Untuk saat ini saya masih menggun… Read More
  • Contoh Program Sederhana C++ 1. Program menentukan angka ganjil dan genap 2. Program perhitungan angka 3. Program menentukan umur 4. Program menu dengan menggunakan IF 5. Program menu dengan menggunakan SWITCH CASE 6. Progra… Read More

0 komentar:

Posting Komentar