Benutzer-Werkzeuge

Webseiten-Werkzeuge


en:tkinter

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
en:tkinter [2022/03/03 22:38] – [Scale] roehneren:tkinter [2022/08/21 18:06] (aktuell) – [Tkinter] roehner
Zeile 2: Zeile 2:
 A GUI form is built with the help of widgets. These are the graphical components available in the Tkinter toolbar. The basics for using widgets are given below, which is sufficient in many cases. More detailed information can be found e.g. in the [[https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/index.html| Tkinter Reference]]. A GUI form is built with the help of widgets. These are the graphical components available in the Tkinter toolbar. The basics for using widgets are given below, which is sufficient in many cases. More detailed information can be found e.g. in the [[https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/index.html| Tkinter Reference]].
  
-A GUI program is created using the {{:tkinter.png}} icon for new Tk/TTK application on the //Program// tab. Widgets can be placed by drag and drop or by clicking on a widget and then clicking in the GUI form. Only absolute layout is supported. This is sufficient for school purposes. Designing a GUI surface with layout managers is much more difficult.+A GUI program is created using the {{:tkapp.png}} icon for new Tk/TTK application on the //Program// tab. Widgets can be placed by drag and drop or by clicking on a widget and then clicking in the GUI form. Only absolute layout is supported. This is sufficient for school purposes. Designing a GUI surface with layout managers is much more difficult.
  
 Attributes and events of a widget are configured in the object inspector. Initially, only the most important attributes and events are displayed. This filtering simplifies working with the object inspector. You can display more or all attributes and methods in two further stages. Attributes and events of a widget are configured in the object inspector. Initially, only the most important attributes and events are displayed. This filtering simplifies working with the object inspector. You can display more or all attributes and methods in two further stages.
Zeile 14: Zeile 14:
 The Python code of a GUI program is saved with the .pyw file extension, the associated form with the .pfm file extension. Both will open together. If you close the form, you can open it again using the {{:arrange.png}} icon in the editor toolbar. The Python code of a GUI program is saved with the .pyw file extension, the associated form with the .pfm file extension. Both will open together. If you close the form, you can open it again using the {{:arrange.png}} icon in the editor toolbar.
  
-==== Labels ====+==== Label ====
 {{:label.png}} {{:label.png}}
-label widget is used to label widgets of a GUI form. It can display text, an image, or both.+Label widget is used to label widgets of a GUI form. It can display text, an image, or both.
 To display an image, select the desired image file in the object inspector for the //Image// attribute.\\ To display an image, select the desired image file in the object inspector for the //Image// attribute.\\
  
Zeile 27: Zeile 27:
 ==== Entry==== ==== Entry====
 {{:entry.png}} {{:entry.png}}
-An Entry widget can be used to enter text or a number. The entered text is obtained via the get() method of the control variable CV belonging to the Entry widget.+An Entry widget can be used to enter or output text or a number. The entered text is obtained via the get() method of the control variable CV belonging to the Entry widget.
  
 Example:  Example: 
Zeile 41: Zeile 41:
 ==== Text ==== ==== Text ====
 {{:text.png}} {{:text.png}}
-In contrast to the Entry widget, a text widget represents a multi-line text. You can enter the text in the object inspector. At runtime, you can use the method shown in the example to output line by line to a text widget named Output. The lines are separated from each other by the control character "\n" (new line).+In contrast to the Entry widget, a Text widget represents a multi-line text. You can enter the text in the object inspector. At runtime, you can use the method shown in the example to output line by line to a Text widget named Output. The lines are separated from each other by the control character "\n" (new line).
  
 Beispiel: Beispiel:
Zeile 68: Zeile 68:
 {{:en:checkbutton.png}} {{:en:checkbutton.png}}
 <code python>  if (cbSelectedCV.get() == 0): </code> <code python>  if (cbSelectedCV.get() == 0): </code>
-\\ 
-\\ 
 ---- ----
 ==== RadiobuttonGroup ==== ==== RadiobuttonGroup ====
 {{:radiobuttongroup.png}}\\ {{:radiobuttongroup.png}}\\
-A RadiobuttonGroup offers several selection possibilities from which you can select an option. A newly created RadiobuttonGroup automatically has the three options "America, Europe and Asia" and the label " Continent ". In the object inspector, you can find these values in the //Items// or //Label_// attribute and can easily adjust them there. If the RadiobuttonGroup should not have a frame delete the label.+A RadiobuttonGroup offers several selection possibilities from which you can select an option. A newly created RadiobuttonGroup automatically has the three options "America, Europe and Asia" and the label " Continent ". In the object inspector, you can find these values in the //Items// respectively //Label_// attribute and can easily adjust them there. If the RadiobuttonGroup should not have a frame delete the label.
  
 The RadiobuttonGroup has a control variable CV that can be used to input or output the selected option: The RadiobuttonGroup has a control variable CV that can be used to input or output the selected option:
Zeile 83: Zeile 81:
   self.rbgContinentCV.set('Asia')   self.rbgContinentCV.set('Asia')
 </code> </code>
- 
- 
-\\ 
 ---- ----
 ==== Listbox ==== ==== Listbox ====
Zeile 93: Zeile 88:
  
 The list box has a control variable CV that gives access to all strings. For accessing the //selected// strings the list box has specific methods. //curselection()// returns a tuple with all positions of selected strings and //get(i)// the string at position i. The list box has a control variable CV that gives access to all strings. For accessing the //selected// strings the list box has specific methods. //curselection()// returns a tuple with all positions of selected strings and //get(i)// the string at position i.
- 
  
 Examples: Examples:
Zeile 120: Zeile 114:
   print(self.spinbox1CV.get())   print(self.spinbox1CV.get())
 </code> </code>
-\\ +----
 ==== Scrollbar ==== ==== Scrollbar ====
 {{:scrollbar.png}} {{:scrollbar.png}}
  
 A Scrollbar can be used to scroll, in which the visible section of a displayed text or graphic is moved. Some widgets such as Entry, Text, Listbox or Canvas can easily be provided with horizontal or vertical scrollbars using the //Scrollbar// attribute. A Scrollbar can be used to scroll, in which the visible section of a displayed text or graphic is moved. Some widgets such as Entry, Text, Listbox or Canvas can easily be provided with horizontal or vertical scrollbars using the //Scrollbar// attribute.
- 
-\\ 
 ---- ----
 ==== Message==== ==== Message====
Zeile 133: Zeile 124:
  
 The Message widget is similar to the Label widget, but is intended for displaying multiple lines of text. The Message widget is similar to the Label widget, but is intended for displaying multiple lines of text.
- 
-\\ 
 ---- ----
 ==== Canvas==== ==== Canvas====
Zeile 148: Zeile 137:
  
 A documentation of the drawing commands can be found under [[https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/canvas.html]]. A documentation of the drawing commands can be found under [[https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/canvas.html]].
- 
-\\ 
 ---- ----
 ==== Frame ==== ==== Frame ====
 {{:frame.png}} {{:frame.png}}
-A Frame is a container for other widgets. For example, the RadiobuttonGroup is a Frame that contains Radiobuttons. Frames are a good way to structure graphic interfaces.+A Frame is a container for other widgets. For example, the RadiobuttonGroup is a Frame that contains Radiobuttons. Frames are a good way to structure graphical interfaces. 
  
 To place a widget in a Frame, click on it in the Tkinter toolbar and then click in the Frame. To place a widget in a Frame, click on it in the Tkinter toolbar and then click in the Frame.
-\\ 
 ---- ----
 ==== LabelFrame ==== ==== LabelFrame ====
 {{:labelframe.png}} {{:labelframe.png}}
-A LabelFrame is a Frame that also has border with an integrated label. +A LabelFrame is a Frame that also has an additional border with an integrated label.
-\\+
 ---- ----
 +
 ==== Scale ==== ==== Scale ====
 {{:scale.png}} {{:scale.png}}
Zeile 217: Zeile 203:
         pass         pass
 </code> </code>
-\\ 
 ---- ----
 ==== PopupMenu ==== ==== PopupMenu ====
Zeile 234: Zeile 219:
         pass         pass
 </code> </code>
-\\ +----
----+
 ==== Menubutton ==== ==== Menubutton ====
 {{:menubutton.png}} A Menubutton is a button that displays a PopupMenu when clicked. {{:menubutton.png}} A Menubutton is a button that displays a PopupMenu when clicked.
 The PopupMenu must also be created and then entered in the //Menu// attribute of the Menubutton. The PopupMenu must also be created and then entered in the //Menu// attribute of the Menubutton.
-\\+---- 
 +==== OptionMenu ==== 
 +{{:optionmenu.png}} With an OptionMenu you can select an item from a given string list in the manner of a menu. The string list is specified in the //MenuItems// attribute. 
 + 
 +The selected option is accessed via the CV control variable. 
 + 
 +<code python> 
 +    print(self.optionMenu1CV.get()) 
 +</code>
 ---- ----
  
en/tkinter.1646343531.txt.gz · Zuletzt geändert: 2022/03/03 22:38 von roehner