You can use
keywords=[<number>]{<list of keywords>}
to add another set of keywords and then
keywordstyle={[<number>]<style commands>},
to give a style for this new set.
Since I didn't have the original definitions for your colors nor of the \ttb command, in the example below I used some own settings, but you can easily use your own settings; the code was randomly taken, just for this example.
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{bera}% optional; just for the example
\lstset{
language=Python,
basicstyle=\ttfamily,
otherkeywords={self},
keywordstyle=\ttfamily\color{blue!90!black},
keywords=[2]{True,False},
keywords=[3]{ttk},
keywordstyle={[2]\ttfamily\color{yellow!80!orange}},
keywordstyle={[3]\ttfamily\color{red!80!orange}},
emph={MyClass,__init__},
emphstyle=\ttfamily\color{red!80!black},
stringstyle=\color{green!80!black},
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
def under_attack(col, queens):
left = right = col
for r, c in reversed(queens):
left, right = left - 1, right + 1
if c in (left, col, right):
return True
return False
print 'This generation has {0} babies'.format(babies)
ttk.Button(buttonframe,width = 3,
textvariable=guivars["%s %s" %(current, item)],
command=lambda: remoteButton(current, item))
\end{lstlisting}
\end{document}
Please notice that "ttk" is being treated as a keyword with red color, as was also requested.
The %& -shell-escape
first line is not sufficient to enable shell escape with TeX Live (MacTeX). This is confirmed by your log: you have
This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013)
restricted \write18 enabled.
while it should be
This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013)
\write18 enabled.
with shell escape enabled.
Here's how you can do with TeXworks.
Open the Preferences panel in TeXworks and go to the Typesetting tab
Click on the “+” button in the lower part
Now fill in the “Tool configuration” window as shown below
For adding a line in the “Arguments” section, click on the “+” button (three times, in this case).
Use the following first line in your document
% !TEX program = XeLaTeX+shell-escape
so that the typesetting tool will be the one just created.
The complete file will then be
% !TEX program = XeLaTeX+shell-escape
\documentclass{article}
\usepackage{python}
\begin{document}
Say hello Python:
\begin{python}%
print "hi"
\end{python}%
\end{document}
Here's the result after hitting the “compile” button:
You might add the --shell-escape
argument to the standard XeLaTeX tool, but it's better not doing it, as shell escape should be enabled with caution only for “safe” file (your files or those coming from a trusted source).
Best Answer
Use
\lstset
. Here is a MWE:The above code will give you this: