Cerca

Heus ací els resultats de la cerca.

2.3 A small lexicon of widgets - Part 3
56 Resultats, Darrera modificació:
widget doesn’t take the focus itself. Run the code and test its behavior. <code python> import tkinter as tk def digits_only(*args): global last_... y.pack() entry.focus_set() window.mainloop() </code> Try to modify the code to allow the user to enter not more than five digits. The last part of our
2.4 Shaping the main window and conversing with the user
46 Resultats, Darrera modificació:
uld use a method named ''title()''. Our sample code shows a window which changes its title each time ... t ten times, after which the title remains 0. <code python> import tkinter as tk def click(*args): ... .bind("<Button-1>", click) window.mainloop() </code> Changing the main window’s icon is more trouble... gree it’s not very elegant. Take a look at the code we've provided in the editor. <code python> impo
2.5 Working with the Canvas
46 Resultats, Darrera modificació:
tart with a simple example. Take a look at the code. <code python> import tkinter as tk window = tk.Tk() canvas = tk.Canvas(window, width=400, height=... (row=0) button.grid(row=1) window.mainloop() </code> It creates a 400 x 400-pixel **canvas** with a ... the Quit button. Can you find the parts of the code responsible for all these actions? {{:info:curso
1.2 Let TkInter speak!
44 Resultats, Darrera modificació:
cilities is to import the package as a whole: <code python>import tkinter</code> Note: it won’t allow you to access some modules built-in within the pac... * looks shorter than **tkinter**, doesn’t it? <code python>import tkinter as tk</code> Okay, we know there’s no accounting for taste, but it’s definite
1.6 Events and how to handle them
43 Resultats, Darrera modificació:
it needs **two arguments** which are strings: <code ; output> messagebox.showinfo(title, info) </code> * the **first** string will be used by the func... the **second** string is a message to display inside the box; the string can be of **any length** (but... es. In the editor we've provided a very simple code demonstrating how ''showinfo()'' works: <code py
1.7 Visiting widgets’ properties
29 Resultats, Darrera modificació:
based on using a **dictionary** which exists inside every widget. Assuming that a widget named ''Widg... value, you can do this in the following way: <code python> old_val = Widget["prop"] Widget["prop"] = new_val </code> Let’s see it in action. Look at the example we've provided in the editor. <code python> import tkinter as tk def on_off():
1.3 Settling widgets in the window's interior
27 Resultats, Darrera modificació:
of putting the widgets (not only the buttons) inside windows. There are more of them than just ''place... r to place some of them, partially or fully, outside the window. If you don't want to deploy the widg... p-left corner. Let's see them all in action. <code python> import tkinter as tk window = tk.Tk() bu... button_3.place(x=30, y=70) window.mainloop() </code> The snippet we've prepared for you shows how th
2.2 A small lexicon of widgets - Part 2
26 Resultats, Darrera modificació:
''Label'' widget displays some lines of text inside the window: <code python> label = Label(master, option, ...) </code> The ''Label'' widget contains two usable properti... ntinuously** update the ''Label''’s contents. <code python> import tkinter as tk def to_string(x):
1.5 A simple GUI application
24 Resultats, Darrera modificació:
ow and launch an event controller – look at the code in the editor to see how to do it. <code python> import tkinter as tk window = tk.Tk() window.mainloop() </code> Our window looks like this one for now: {{ :inf... e changed at any moment of the widget's life. <code python> import tkinter as tk window = tk.Tk() l
1.8 Interacting with widget methods
21 Resultats, Darrera modificació:
uming that ''Widget'' is an existing widget): <code python> Widget.after(time_ms, function) Widget.after_cancel(id) </code> * ''after()'' – this method expects two argume... it than telling you a long and winding story. <code python> import tkinter as tk def blink(): g... r(500, blink) frame.pack() window.mainloop() </code> The code we’ve written to demonstrate how the '
1.9 Looking at variables
17 Resultats, Darrera modificació:
to store values which are accessible to the outside world) but there is something more – any change o... g type, you’ll create it in the following way: <code python> s = StringVar() </code> If you want to **assign a value** to an observable variable, you hav... tring to a variable of the ''StringVar'' kind: <code python> strng.set("To be or not to be") </code> I
2.1 A small lexicon of widgets - Part 1
15 Resultats, Darrera modificació:
he widget that owns the newly created object. <code python> widget = Widget(master, option, ... ) </code> The master widget is just the main window in mo... sted:20231228-105137.png}} Analyze and run the code in the editor – we wrote it to show you some of t... he button’s properties and methods in action. <code python> import tkinter as tk def switch():
Python Professional Course Series: GUI Programming
13 Resultats, Darrera modificació:
construction of such equipment and became worldwide industry standards. The first of them is the [[ht... fferent from contemporary keyboards installed inside laptops) and nothing more. Some of the terminals... on't be surprised. One of the widgets living inside a particular window owns the focus. The widget (w... ython-pcpp1:m3:pasted:20231222-020402.png }} Inside the title bar there is (or can be) a set of contr
1.4 Coloring your widgets
13 Resultats, Darrera modificació:
ts == Adding colors Nearly everything you put inside your windows may be **colored**. Most widgets hav... f tkinter understands **English** – look at the code in the editor, our test is there. <code python> import tkinter as tk window = tk.Tk() button = tk.B... fg="yellow") button.pack() window.mainloop() </code> Note the two new arguments we use in the constr