Ready to Start Your Career?
January 1, 2016
Module 4: Ctypes On Linux
January 1, 2016
January 1, 2016
Hi, I am a little bit stuck on ctypes... I am working on a Linux machine and while I understand the material, I am having a problem with adjusting the code to Linux. Is there an alternative to windll in Linux? And is there some easy way of creating message box (maybe gtk+ or something...) Thanks I have the same issue with ctypes :) there are libraries to create a gui, qt, tk, tkinter, maybe others. I wouldn't exactly call any of them "easy" though. but if you go to https://filmsbykris.com and look in the playlists, he has some very good videos explaining how to use gtk for guis Thanks on your answer. There are some useful tips in those videos, but I was thinking more on how to do it with ctypes. I have some ideas, but I cannot find linux alternative for windll (if there is any...). same question. this lecture doesnt seem to really relate to non windows users at all. Answer is on this page peoples.... https://docs.python.org/2/library/ctypes.html "On Linux, it is required to specify the filename including the extension to load a library, so attribute access can not be used to load libraries. Either the LoadLibrary() method of the dll loaders should be used, or you should load the library by creating an instance of CDLL by calling the constructor: >>> >>> cdll.LoadLibrary("libc.so.6") >>> libc = CDLL("libc.so.6") >>> libc >>>" That's answer to just a part of the question. First, it is not stated if cdll is usable in all the places (including the places where windll would be used on windows), or not? And second, this is ok way for using ctypes on linux, but my question was more specific: Is there an easy way for creating message box using ctypes on linux? I know there are a ways of doing it with python and I guess that there are “complicated” ways of doing it in linux with ctypes, but is there some way of doing it with ctypes on linux (preferably debian based) in elegant and simple way like it was done on windows? I am aware that this was just an example of using ctypes in python, but I am curious... :) Ctypes is an interface to basic C data types. E.G int, char etc. If you want to display a window, mesagebox etc (either in Linux or Windows), you need to access the appropriate libraries. Ctypes don't provide that functionality. As Koert said above, there are Linux specific libraries for building a messagebox. But I can tell you from experience, they are not easy A quick search found this code (just tested in Kali Linux....) although I get GTK warnings..... import subprocess as SP # call an OS subprocess $ zenity --entry --text "some text" # (this will ask OS to open a window with the dialog) res=SP.Popen(\['zenity','--entry','--text', 'please write some text'\], stdout=SP.PIPE) # get the user input string back usertext=str(res.communicate()\[0\]\[:-1\]) # adjust user input string text=usertext\[2:-1\] print("I got this text from the user: %s"%text) there is also (apparently easygui which doesn't use ctypes tho....... This works with no errors import easygui easygui.msgbox("This is a message!", title="simple gui") @andec I did not know easygui thanks bringing it up here. I'll have to look in to that. Koert
Build your Cybersecurity or IT Career
Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry