Cerca

Heus ací els resultats de la cerca.

2.4 Shaping the main window and conversing with the user
45 Resultats, Darrera modificació:
would use a method named ''title()''. Our sample code shows a window which changes its title each time ... it ten times, after which the title remains 0. <code python> import tkinter as tk def click(*args): ... ow.bind("<Button-1>", click) window.mainloop() </code> Changing the main window’s icon is more trouble... agree 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
42 Resultats, Darrera modificació:
start 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=40... id(row=0) button.grid(row=1) window.mainloop() </code> It creates a 400 x 400-pixel **canvas** with a ... g the Quit button. Can you find the parts of the code responsible for all these actions? {{:info:curso
1.6 Events and how to handle them
41 Resultats, Darrera modificació:
d it needs **two arguments** which are strings: <code ; output> messagebox.showinfo(title, info) </code> * the **first** string will be used by the functi... ties. In the editor we've provided a very simple code demonstrating how ''showinfo()'' works: <code python> import tkinter from tkinter import messagebox
1.2 Let TkInter speak!
37 Resultats, Darrera modificació:
facilities 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 packa... k** 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 definitely
2.3 A small lexicon of widgets - Part 3
34 Resultats, Darrera modificació:
he 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_st... try.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 st
1.7 Visiting widgets’ properties
26 Resultats, Darrera modificació:
ew 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(): ... lace(x=50, y=100, width=100) window.mainloop() </code> Note: we use the text property to: * **diagno
1.3 Settling widgets in the window's interior
18 Resultats, Darrera modificació:
top-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... ould look different now – can we be sure of it? <code python> import tkinter as tk window = tk.Tk() bu... place(x=30, y=70, height=50) window.mainloop() </code> Yes, we can! {{ :info:cursos:pue:python-pcpp1:
1.5 A simple GUI application
18 Resultats, Darrera modificació:
ndow 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... be 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
16 Resultats, Darrera modificació:
ssuming that ''Widget'' is an existing widget): <code python> Widget.after(time_ms, function) Widget.after_cancel(id) </code> * ''after()'' – this method expects two argume... n it than telling you a long and winding story. <code python> import tkinter as tk def blink(): g... ter(500, blink) frame.pack() window.mainloop() </code> The code we’ve written to demonstrate how the '
1.9 Looking at variables
16 Resultats, Darrera modificació:
ing 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 have ... string to a variable of the ''StringVar'' kind: <code python> strng.set("To be or not to be") </code> If you need to **use the value** stored in a variable,
2.2 A small lexicon of widgets - Part 2
16 Resultats, Darrera modificació:
t displays some lines of text inside the window: <code python> label = Label(master, option, ...) </code> The ''Label'' widget contains two usable properties... continuously** update the ''Label''’s contents. <code python> import tkinter as tk def to_string(x): ... tring(counter)) label.pack() window.mainloop() </code> The ''Message'' widget is very similar to the '
2.1 A small lexicon of widgets - Part 1
15 Resultats, Darrera modificació:
the widget that owns the newly created object. <code python> widget = Widget(master, option, ... ) </code> The master widget is just the main window in mos... pasted:20231228-105137.png}} Analyze and run the code in the editor – we wrote it to show you some of the button’s properties and methods in action. <code python> import tkinter as tk def switch():
1.4 Coloring your widgets
10 Resultats, Darrera modificació:
if 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.But... , fg="yellow") button.pack() window.mainloop() </code> Note the two new arguments we use in the constr... use them – we've showed our try in the editor. <code python> import tkinter as tk window = tk.Tk() b
Python Professional Course Series: GUI Programming
6 Resultats, Darrera modificació:
avior, making the coding extremely heavy, and the code becomes badly bloated. In a slightly more sugges... r, triple, and so on. Let's try to imagine it. <code> while True: wait_for_user_action() if us... elif isfocused(button_no): : : : </code> Note: The pseudo-code is deprived of all details. Moreover, it's not complete. It covers less than ab