Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

Python How many of you use TKinter ?, Python GUI

views
     
TSFlierMate1
post Jun 4 2022, 12:22 PM, updated 4y ago

Getting Started
**
Validating
139 posts

Joined: Jun 2022
I thought Python is only console screen, today I discovered that Python has GUI library called TKinter.

Example code:
CODE
import tkinter as tk
from tkinter import messagebox

win = tk.Tk()

def hello():
   messagebox.showinfo('Info','Hello, world')

win.title('Python GUI example')

win.geometry('400x300')

btn1=tk.Button(win,text='Click me',command=hello).grid(column=0,row=0)

win.mainloop()


How many here know Tkinter, and use it?

Is it a standard and universal lib across various versions of Python?

Example output of code above:
user posted image
Buffalo Soldier
post Jun 4 2022, 12:28 PM

Casual
***
Junior Member
445 posts

Joined: Aug 2005
Wait till you meet WxPython
15cm
post Jun 4 2022, 12:46 PM

Casual
***
Junior Member
423 posts

Joined: Apr 2022
tkinter is the first GUI everyone uses when they learn python

but i dont use it much because i use python more as script for automation
TSFlierMate1
post Jun 4 2022, 02:43 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(Buffalo Soldier @ Jun 4 2022, 12:28 PM)
Wait till you meet WxPython
*
Thanks for telling me this, I will stick to Tkinter in the mean time.

QUOTE
wxPython is easier to work with than Tkinter. You can get things up and running more easily and with less "voodoo" code. Both platforms claim to be cross-platform, but both still have issues on Mac OS-X, a platform I must support.
9 Nov 2010

From the article "Choosing wxPython over Tkinter" - wiki.wxpython.org

QUOTE(15cm @ Jun 4 2022, 12:46 PM)
tkinter is the first GUI everyone uses when they learn python

but i dont use it much because i use python more as script for automation
*
Alright, so finally I am like every Python beginner, get the chance to learn first GUI in Python. laugh.gif


Lord Tiki Mick
post Jun 4 2022, 09:39 PM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
I know about it but I'm not using it. I prefer to use GTK with python when I was using Linux as my main OS. Now I don't do desktop UI anymore.
flashang
post Jun 4 2022, 11:31 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


Will always convince user use web app.
Only create desktop gui app when have to.

I use tkinter because lazy to install other ui library.
It enough to solve the problem -
create a gui interface for user could use the software easily.

smile.gif


15cm
post Jun 5 2022, 08:28 PM

Casual
***
Junior Member
423 posts

Joined: Apr 2022
QUOTE(FlierMate1 @ Jun 4 2022, 02:43 PM)
Thanks for telling me this, I will stick to Tkinter in the mean time.

9 Nov 2010

From the article "Choosing wxPython over Tkinter" - wiki.wxpython.org
Alright, so finally I am like every Python beginner, get the chance to learn first GUI in Python.  laugh.gif
*
what IDE do you use ? for python and for others
TSFlierMate1
post Jun 5 2022, 08:45 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(15cm @ Jun 5 2022, 08:28 PM)
what IDE do you use ? for python and for others
*
I use Visual Studio 2022 to code for Python project.
TSFlierMate1
post Jun 6 2022, 03:45 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(Lord Tiki Mick @ Jun 4 2022, 09:39 PM)
I know about it but I'm not using it. I prefer to use GTK with python when I was using Linux as my main OS. Now I don't do desktop UI anymore.
*
Good to know about your feedback. I think GTK is more about screen layout in XML script. Hmm.


QUOTE(flashang @ Jun 4 2022, 11:31 PM)
Will always convince user use web app.
Only create desktop gui app when have to.

I use tkinter because lazy to install other ui library.
It enough to solve the problem -
  create a gui interface for user could use the software easily.

smile.gif
*
Other UI libraries like wxPython, from my quick web search, are extension to be installed separately.
It is good that Tkinter comes bundled with the Python installation itself.
Lord Tiki Mick
post Jun 6 2022, 04:16 PM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
QUOTE(FlierMate1 @ Jun 6 2022, 03:45 PM)
Good to know about your feedback. I think GTK is more about screen layout in XML script. Hmm.
Other UI libraries like wxPython, from my quick web search, are extension to be installed separately.
It is good that Tkinter comes bundled with the Python installation itself.
*
The XML template is a facility, you can always build the UI using python code. E.g: (if I remember correctly)

CODE

from gi.repository import Gtk

win = Gtk.Window()
box = Gtk.VBox()
win.add(box)
b1 = Gtk.Button("Foo")
box.add(b1)
b2 = Gtk.Button("Bar")
box.add(b2)

win.show()
Gtk.main()

TSFlierMate1
post Jun 16 2022, 04:36 AM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
user posted image

user posted image

This post has been edited by FlierMate1: Aug 6 2022, 03:54 PM


Attached File(s)
Attached File  exemaker.zip ( 49.15k ) Number of downloads: 8
TSFlierMate1
post Jun 16 2022, 03:10 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
There seems like no way to define struct like this in Python:
CODE
       public struct IMAGE_DATA_DIRECTORY
       {
           public UInt32 VirtualAddress;
           public UInt32 Size;
       }


How to do it in Python? Currently I use bytearray in which I cannot assign meaningful name to each value.
angch
post Jun 16 2022, 04:40 PM

On my way
****
Junior Member
636 posts

Joined: Jul 2006
CODE
class IMAGE_DATA_DIRECTORY:
   VirtualAddress = int(0)
   Size = int(0)

   def __init__(self, v, s):
       self.VirtualAddress = v
       self.Size = s

a = IMAGE_DATA_DIRECTORY(123, 456)

print(a.__dict__)


This post has been edited by angch: Jun 16 2022, 04:44 PM
TSFlierMate1
post Jun 16 2022, 05:12 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(angch @ Jun 16 2022, 04:40 PM)
CODE
class IMAGE_DATA_DIRECTORY:
   VirtualAddress = int(0)
   Size = int(0)

   def __init__(self, v, s):
       self.VirtualAddress = v
       self.Size = s

a = IMAGE_DATA_DIRECTORY(123, 456)

print(a.__dict__)

*
Perfect, although it is a little difficult for beginner.

I can also use:
CODE

a.VirtualAddress=1234
print(a.VirtualAddress)


Thanks angch.
Lord Tiki Mick
post Jun 19 2022, 01:51 AM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
QUOTE(FlierMate1 @ Jun 16 2022, 05:12 PM)
Perfect, although it is a little difficult for beginner.

I can also use:
CODE

a.VirtualAddress=1234
print(a.VirtualAddress)


Thanks angch.
*
Nowadays you'd do this with dataclass

CODE

from dataclasses import dataclass

@dataclass
class ImageDataDir:
   virtAddr: int
   szie: int

TSFlierMate1
post Jun 19 2022, 12:20 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(Lord Tiki Mick @ Jun 19 2022, 01:51 AM)
Nowadays you'd do this with dataclass

CODE

from dataclasses import dataclass

@dataclass
class ImageDataDir:
   virtAddr: int
   szie: int

*
Learned something new again, but this dataclass is not part of default installation:

QUOTE
  Message=No module named 'dataclasses'
So I think I will strike a balance between your solution and angch's, hehe:

CODE

class IDD:
   Addr=int(0)
   Size=int(0)

b=IDD

b.Addr=1024
print(IDD.Addr)


This works exactly what I want.


Lord Tiki Mick
post Jun 19 2022, 07:28 PM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
QUOTE(FlierMate1 @ Jun 19 2022, 12:20 PM)
Learned something new again, but this dataclass is not part of default installation:
So I think I will strike a balance between your solution and angch's, hehe:

CODE

class IDD:
   Addr=int(0)
   Size=int(0)

b=IDD

b.Addr=1024
print(IDD.Addr)


This works exactly what I want.
*
Don't tell me you're still using python2 which is supposed to be dead. dataclass is part of python since 3.7.
angch
post Jun 19 2022, 08:15 PM

On my way
****
Junior Member
636 posts

Joined: Jul 2006
QUOTE(FlierMate1 @ Jun 19 2022, 12:20 PM)
Learned something new again, but this dataclass is not part of default installation:
So I think I will strike a balance between your solution and angch's, hehe:

CODE

class IDD:
   Addr=int(0)
   Size=int(0)

b=IDD

b.Addr=1024
print(IDD.Addr)


This works exactly what I want.
*
Invision doesn't have history, but if it had, you'd see that that was exactly what I posted before I edited it for completeness. Depends on what you wanna do, but please don't reinvent your favourite language in other languages. (e.g. expecting low level typing over what's canonical in that language).

When in Python, do it the Pythonic way. Use dataclasses, it's cleaner. Apologies for not using it earlier, Python isn't my main language.

https://docs.python.org/3/library/dataclasses.html

This post has been edited by angch: Jun 19 2022, 08:16 PM
TSFlierMate1
post Jun 19 2022, 10:11 PM

Getting Started
**
Validating
139 posts

Joined: Jun 2022
QUOTE(Lord Tiki Mick @ Jun 19 2022, 07:28 PM)
Don't tell me you're still using python2 which is supposed to be dead. dataclass is part of python since 3.7.
*
Mine is 3.6, the version downloaded automatically by Visual Studio 2022.

Thank you for revealing to me there is dataclass. Your recent participation in my discussion topic is very much appreciated.

QUOTE(angch @ Jun 19 2022, 08:15 PM)
Invision doesn't have history, but if it had, you'd see that that was exactly what I posted before I edited it for completeness. Depends on what you wanna do, but please don't reinvent your favourite language in other languages. (e.g. expecting low level typing over what's canonical in that language).

When in Python, do it the Pythonic way. Use dataclasses, it's cleaner. Apologies for not using it earlier, Python isn't my main language.
*
Looks like dataclasses (according the link you posted) has built-in __init__, in which your first example code defined it manually.
At least now I know there are two ways to define struct (like that of C#) in Python. Your diligence in answering many of the coding questions is also much appreciated.


Lord Tiki Mick
post Jun 20 2022, 12:28 AM

Regular
******
Senior Member
1,020 posts

Joined: Jul 2012
QUOTE(FlierMate1 @ Jun 19 2022, 10:11 PM)
Mine is 3.6, the version downloaded automatically by Visual Studio 2022.

Thank you for revealing to me there is dataclass. Your recent participation in my discussion topic is very much appreciated.
Looks like dataclasses (according the link you posted) has built-in __init__, in which your first example code defined it manually.
At least now I know there are two ways to define struct (like that of C#) in Python. Your diligence in answering many of the coding questions is also much appreciated.
*
It's not only two, they're other ways. sweat.gif

For example, you can also use namedtuple & dict

CODE

# namedtuple
IDD = namedtuple('IDD', ['addr', 'size'])
idd = IDD(0, 0)

# dict
idd = {"addr": 0, "size"} # you directly assign the data.

# dict with type hinting
class IDD(TypedDict):
   addr: int
   size: int

idd: IDD = {"addr": 0, "size"} # you directly assign the data, but you provide type hint for variable


2 Pages  1 2 >Top
 

Change to:
| Lo-Fi Version
0.0150sec    0.23    6 queries    GZIP Disabled
Time is now: 25th December 2025 - 01:39 AM