Jump to content

Serverele RPG vor primi un rollback de pe 09.05.2021 05:00. Detalii aici

Recrutăm designeri audio și video. Aplicați aici

Sign in to follow this  
D J C

[Python] Programming With Tkinter

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

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.