Jump to content
Hostul a fost schimbat. Daca vedeti serverul offline readaugati rpg.b-zone.ro sau 141.95.124.78:7777 in clientul de sa-mp ×

[Python] Programming With Tkinter


D J C
 Share

Recommended Posts

P1ziOZx.png

 

Build Your First Python GUI Application With Tkinter

 

 

 

You can use any device to script this program. the first thing you need to do is import the Python GUI Tkinter module:

from tkinter import *

 

A window is an instance of Tkinter’s Tk class. Go ahead and create a new window and assign it to the variable window:

window = Tk()

 

To add the title to your GUI application you can write this line:

window.title("B-Zone")

 

In addition, you need to write a loop for your application. Because if you do not write,

it can create problems in the work, for example, crash or application gonna closed in 1 second or something like that.

 

The gonna make loop for the "Window" label:

window.mainloop()

 

Now the code might look like this:

from tkinter import *

window = Tk()
window.title("B-Zone")

window.mainloop()

 

Preview

xGr1W9k.png

__________________________

 

 

I would to Adding a Widget/Text to the program, So what should I do? Use the Label class to add some text to a window. Create a Label widget with the text "Hi, B-Zone" and assign it to a variable called hi:

hi = Label(text="Hi, B-Zone")
hi.pack()

 

Final code + Preview:

from tkinter import *

window = Tk()
window.title("B-Zone")
hi = Label(text="Hi, B-Zone")
hi.pack()

window.mainloop()

 

Preview

j971gBL.png

__________________________

 

We will cover many of the functions of this in the future:

 

  • control the width and height of a label
  • Buttons / Background
  • Getting Multiline User Input With Text Widgets
Edited by D J C
Link to comment
Share on other sites

  • D J C locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.